//
//  ServiceViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 15-5-20.
//  Copyright (c) 2015年 RuiBen. All rights reserved.
//

#import "ServiceViewController.h"
#import "ServiceManagementTableViewCell.h"
#import "OldMeterialTableViewCell.h"

#import "GuideListTableViewCell.h"
#import "OrderDetailTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "ResultTableViewCell.h"
//#import "ServiceSearchProductTableViewCell.h"
#import "HZAreaPickerView.h"
#import <CoreLocation/CoreLocation.h>
#import "EGORefreshTableHeaderView.h"
#import "SearchMemberTableViewCell.h"
#import "FPNumberPadView.h"
#import "searchProductAndMemberTableViewCell.h"
#import "CashierViewController.h"
#import "PrintWebViewController.h"
#import "CommonScanViewController.h"
#import "FilterViewController.h"
#import "CommonProductDetailViewController.h"
@interface ServiceViewController ()<ServiceManagementTableViewCelllDelegate,HZAreaPickerDelegate,EGORefreshTableHeaderDelegate,FPNumberPadViewDelegate,CashierViewControllerDelegate,CommonScanDelegate,FilterViewControllerDelegate,CommonProductDetailDelegate>
{
    FilterViewController *filterVC;
    PrintWebViewController *printWebVC;
    CashierViewController *cashierVC;
    CommonProductDetailViewController *commonProductDetailVC;
    EGORefreshTableHeaderView *_refreshHeaderView;
    CommonScanViewController *commonScanVC;
    BOOL _reloading;

    NSUInteger _PageIndex;
    NSUInteger _TotalCount;
    NSUInteger _TotalPage;
    
    NSUInteger _productPageIndex;
    NSUInteger _productTotalCount;
    NSUInteger _productTotalPage;

    NSMutableArray *serviceNumArray;
    NSMutableArray *serviceNumberArray;
    NSMutableArray *serviceStatusArray;
    NSMutableArray *serviceTypeArray;
    NSMutableArray *serviceGuideNameArray;
    NSMutableArray *serviceMemberNameArray;
    NSMutableArray *serviceDateArray;
    NSMutableArray *serviceProductNameArray;
    NSMutableArray *servicePriceArray;
    NSMutableArray *serviceWeightArray;
    
    NSMutableArray *serviceDetailProductNameArray;
    NSMutableArray *serviceDetailProductPriceArray;
    NSMutableArray *serviceDetailProductUrlArray;
    NSMutableArray *serviceDetailWeightArray;
    NSMutableArray *serviceDetailAttributeArray;
    NSMutableArray *serviceDetailCodeArray;
    NSMutableArray *serviceDetailProductAddressArray;
   
    NSMutableArray *guideNameArray;
    NSMutableArray *guideCodeArray;
    
    
  //  NSMutableArray *cashierGuideNameArray;
  //  NSMutableArray *cashierGuideCodeArray;
    BOOL isOpened;
    NSString *guideCodeStr;
    NSString *memberCodeStr;
    
    NSUInteger serviceListCellTag;
    
    NSMutableArray *findProductImageArray;
    NSMutableArray *findMemberNameArray;
    NSMutableArray *findMemberCodeArray;
    NSMutableArray *findMemberPhoneArray;
    NSMutableArray *findMemberGradeArray;
     NSMutableArray *findMemberSexArray;
    // NSMutableArray *findProductURLArray;
    NSMutableArray *findProductCodeArray;
    NSMutableArray *findProductNameArray;
    NSMutableArray *findProductPriceArray;
    NSMutableArray *findProductWeightArray;
    NSMutableArray *findProductAddressArray;
    NSMutableArray *findProductDateArray;
   
   // NSMutableArray *findmProducts;
    
    BOOL addServiceIsOpen;
    
    NSString *serviceTypeStr;
    NSUInteger searchProductCellTag;
    NSUInteger searchGuideCellTag;
    
    NSMutableArray *featureCodeArray;
    NSMutableArray *featureNameArray;
    NSMutableArray *selectFeatureCodeArray;
    NSString *sexStr;
    
    
    NSInteger buShouYinCellTag;
    
    NSMutableArray *selectedProductImageArray;
    NSMutableArray *selectedProductAddressArray;
    NSMutableArray *selectedProductWeightArray;
    NSMutableArray *selectedProductPriceArray;
    NSMutableArray *selectedProductNameArray;
   // NSMutableArray *selectedStatusArray;
    NSMutableArray *selectedProductCodeArray;

    float cashierAmountFloat;
    float balanceAmountFloat;
    float oldMeterialTotalAmountFloat;
    
     NSString *openIdStr;
    
    UITextField *inputTextField;
    
    
    NSString *selectMemberCodeStr;
    
    BOOL memberGradeIsOpen;
    NSMutableArray *memberGradeNameArray;
    NSMutableArray *memberGradeCodeArray;
    NSString *memberGradeCodeStr;
    
    NSString *integralAvailabalStr;
    
    NSMutableArray *filterTypeCodeArray ;
    NSMutableArray *inputFilterCodeArray;
    NSMutableArray *inputMinResultFilterNameArray;
    NSMutableArray *inputMaxResultFilterNameArray;
    NSMutableArray *selectFilterCodeArray;
    NSMutableArray *selectFilterNameArray;
    NSMutableArray *selectCustomTimeArray ;
    NSMutableArray *customTimeFilterTypeCodeArray ;
    NSString *startTimeStr;
    NSString *endTimeStr;

}
- (void)reloadTableViewDataSource;
- (void)doneLoadingTableViewData;
@property (strong, nonatomic) NSString *areaValue, *cityValue;
@property (strong, nonatomic) HZAreaPickerView *locatePicker;
@end

@implementation ServiceViewController
@synthesize areaValue=_areaValue, cityValue=_cityValue;
@synthesize locatePicker=_locatePicker;

-(void)viewWillAppear:(BOOL)animated
{
    if ([_isLoad isEqualToString:@"N"]) {
    if (commonProductDetailVC.view!=nil) {
            
            [commonProductDetailVC removeFromParentViewController];
            [commonProductDetailVC.view removeFromSuperview];
            
        }

    if (printWebVC.view!=nil) {
        [printWebVC.view removeFromSuperview];
        [printWebVC removeFromParentViewController];
        
    }
    if (cashierVC.view!=nil) {
        [cashierVC.view removeFromSuperview];
        [cashierVC removeFromParentViewController];
        
    }
    if (commonScanVC.view!=nil) {
        if (commonScanVC.timer!=nil) {
            [commonScanVC.timer invalidate];
            commonScanVC.timer=nil;
        }
        if (commonScanVC.captureSession!=nil) {
            
            
            [commonScanVC.captureSession stopRunning];
            commonScanVC.captureSession = nil;
        }
        if (commonScanVC.videoPreviewLayer !=nil) {
            
            
            [commonScanVC.videoPreviewLayer removeFromSuperlayer];
        }
        

        [commonScanVC.view removeFromSuperview];
        [commonScanVC removeFromParentViewController];
        
    }
    if (filterVC.view!=nil) {
        
        [filterVC removeFromParentViewController];
        [filterVC.view removeFromSuperview];
        
    }
    

    [_addServiceButton addTarget:self action:@selector(addServiceButtonClick) forControlEvents:UIControlEventTouchUpInside];
    
    
    [self initServiceListView];
    [self initServiceDetailView];
    [self initCashierViewContainer];
    [self initAddServiceViewContainer];
    [self initAddMember];
    //[self initSearMemberView];
    [self initOrderFilterView];
    _PageIndex=0;
    [self loadServiceListNextPage:_PageIndex];
    }
}
-(void)initAddMember
{
    memberGradeCodeStr=@"";
    integralAvailabalStr=@"";
    memberGradeIsOpen=NO;
    memberGradeNameArray=[NSMutableArray array];
    memberGradeCodeArray=[NSMutableArray array];
    
    guideCodeStr=@"";
    
    isOpened=NO;
    // mFeaturesArray=[NSMutableArray array];
    featureCodeArray=[NSMutableArray array];
    featureNameArray=[NSMutableArray array];
    selectFeatureCodeArray=[NSMutableArray array];
    
    
}

-(void)initOrderFilterView
{
    inputFilterCodeArray=[NSMutableArray array];
    inputMinResultFilterNameArray=[NSMutableArray array];
    inputMaxResultFilterNameArray=[NSMutableArray array];
    filterTypeCodeArray=[NSMutableArray array];
    customTimeFilterTypeCodeArray=[NSMutableArray array];
    selectFilterCodeArray=[NSMutableArray array];
    selectFilterNameArray=[NSMutableArray array];
    selectCustomTimeArray=[NSMutableArray array];
    
    startTimeStr=@"";
    endTimeStr=@"";
    
    [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f]];
    [_orderFilterImage setImage:[UIImage imageNamed:@"shaixuandingdan_.png"]];
    // [_orderFilterViewContainer bringSubviewToFront:_resetFilterBtn];
    
    _orderFilterBtn.layer.borderColor=[[UIColor colorWithRed:220.0f/255.0f green:220.0f/255.0f blue:220.0f/255.0f alpha:1] CGColor];
    _orderFilterBtn.layer.borderWidth= 1.0f;
    _orderFilterBtn.layer.cornerRadius=4;
    
    [_orderFilterBtn addTarget:self action:@selector(orderFilterBtnClick) forControlEvents:UIControlEventTouchUpInside];
}
-(void)orderFilterBtnClick
{
    if (filterVC.view!=nil) {
        
        [filterVC removeFromParentViewController];
        [filterVC.view removeFromSuperview];
        
    }
    filterVC=[[FilterViewController alloc] init];
    filterVC.delegate=self;
    filterVC.docTypeStr=@"Service";
    filterVC.selectCustomTimeArray=[NSMutableArray arrayWithArray:selectCustomTimeArray];
    filterVC.startTimeStr=startTimeStr;
    filterVC.endTimeStr=endTimeStr;
    // NSLog(@"selectFilterNameArray=22222======%@",selectFilterNameArray);
    filterVC.selectFilterNameArray=[NSMutableArray arrayWithArray:selectFilterNameArray];
    filterVC.view.frame = CGRectMake(0,
                                     0,
                                     self.view.bounds.size.width,
                                     self.view.bounds.size.height);
    
    [self addChildViewController:filterVC];
    [self.view addSubview:filterVC.view];
}
-(void)confirmFilterBtnClick:(NSMutableArray *)commonFilterTypeCodeArray commonSelectFilterCodeArray:(NSMutableArray *)commonSelectFilterCodeArray commonInputFilterCodeArray:(NSMutableArray *)commonInputFilterCodeArray commonInputMinResultFilterNameArray:(NSMutableArray *)commonInputMinResultFilterNameArray commonInputMaxResultFilterNameArray:(NSMutableArray *)commonInputMaxResultFilterNameArray commonCustomTimeFilterTypeCodeArray:(NSMutableArray *)commonCustomTimeFilterTypeCodeArray commonSelectCustomTimeArray:(NSMutableArray *)commonSelectCustomTimeArray commonSelectFilterNameArray:(NSMutableArray *)commonSelectFilterNameArray  commonStartTimeStr:(NSString *)commonStartTimeStr commonEndTimeStr:(NSString *)commonEndTimeStr isDefault:(NSString *)isDefault
{
    
    if ([isDefault isEqualToString:@"Y"]) {
        //  NSLog(@"_isDefault0000===%@",isDefault);
        [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f]];
        [_orderFilterImage setImage:[UIImage imageNamed:@"shaixuandingdan_.png"]];
    }
    else{
        // NSLog(@"_isDefault1111===%@",isDefault);
        [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:203.0f/255.0f green:164.0f/255.0f blue:67.0f/255.0f alpha:1.0f]];
        [_orderFilterImage setImage:[UIImage imageNamed:@"yishaixuan_.png"]];
    }
    
    filterTypeCodeArray=commonFilterTypeCodeArray;
    selectFilterCodeArray=commonSelectFilterCodeArray;
    inputFilterCodeArray=commonInputFilterCodeArray;
    inputMinResultFilterNameArray=commonInputMinResultFilterNameArray;
    inputMaxResultFilterNameArray=commonInputMaxResultFilterNameArray;
    customTimeFilterTypeCodeArray=commonCustomTimeFilterTypeCodeArray;
    selectCustomTimeArray=commonSelectCustomTimeArray;
    selectFilterNameArray=commonSelectFilterNameArray;
    
    startTimeStr=commonStartTimeStr;
    endTimeStr=commonEndTimeStr;
    
    [serviceNumArray removeAllObjects];
    [serviceTypeArray removeAllObjects];
    [serviceStatusArray removeAllObjects];
    [serviceNumberArray removeAllObjects];
    [serviceGuideNameArray removeAllObjects];
    [serviceMemberNameArray removeAllObjects];
    [serviceDateArray removeAllObjects];
    [serviceProductNameArray removeAllObjects];
    [servicePriceArray removeAllObjects];
    [serviceWeightArray removeAllObjects];
    
    _PageIndex=0;
    [self loadServiceListNextPage:_PageIndex];
}


-(void)initAddServiceViewContainer
{
    selectedProductImageArray=[NSMutableArray array];
    selectedProductAddressArray=[NSMutableArray array];
    selectedProductWeightArray=[NSMutableArray array];
    selectedProductPriceArray=[NSMutableArray array];
    selectedProductNameArray=[NSMutableArray array];
   // selectedStatusArray=[NSMutableArray array];
    selectedProductCodeArray=[NSMutableArray array];
     [_serviceMoneyTextField addTarget:self action:@selector(updateLabel:)  forControlEvents:UIControlEventEditingDidEnd];
    _searchNoteView.hidden=NO;
    findProductImageArray=[NSMutableArray array];
    findMemberNameArray=[NSMutableArray array];
    findMemberCodeArray=[NSMutableArray array];
    findMemberPhoneArray=[NSMutableArray array];
     findMemberGradeArray=[NSMutableArray array];
    findMemberSexArray=[NSMutableArray array];
    // findProductURLArray=[NSMutableArray array];
    findProductCodeArray=[NSMutableArray array];
    findProductNameArray=[NSMutableArray array];
    findProductPriceArray=[NSMutableArray array];
   // findmProducts=[NSMutableArray array];
    findProductWeightArray=[NSMutableArray array];
    findProductAddressArray=[NSMutableArray array];
    findProductDateArray=[NSMutableArray array];
    
    CGRect frame1=_addServiceViewContainer.frame;
    frame1.origin.y=768;
    [_addServiceViewContainer setFrame:frame1];
     [_resultAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_searchProductAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_searchProductAlphaView addTarget:self action:@selector(searchProductAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
    
    addServiceIsOpen=NO;
    CGRect frame=_addServiceSearchResultViewContainer.frame;
    
    frame.origin.y=768;
    [_addServiceSearchResultViewContainer setFrame:frame];
    
    
//    _resultProductImageView.layer.borderWidth =1;
//    _resultProductImageView.layer.cornerRadius=10;
//    _resultProductImageView.layer.borderColor = [[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
//    
    [_resultAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_resultAlphaView addTarget:self action:@selector(resultAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
    
    _resultGuideListViewContainer.hidden=YES;
   
        
        UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
        [_resultGuideListArrowImage setImage:closeImage];
        CGRect framea=_resultGuideListViewContainer.frame;
        
        framea.size.height=1;
        [_resultGuideListViewContainer setFrame:framea];

    _resultGuideListBtn.tag=50;
     [_resultGuideListBtn addTarget:self action:@selector(selectGuideBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    _resultTextView.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
    _resultTextView.layer.borderWidth= 1.0f;
    _resultTextView.layer.cornerRadius=3;

    [_qinXiButton addTarget:self action:@selector(serviceTypeClick:) forControlEvents:UIControlEventTouchUpInside];
     [_mainTainButton addTarget:self action:@selector(serviceTypeClick:) forControlEvents:UIControlEventTouchUpInside];
     [_otherButton addTarget:self action:@selector(serviceTypeClick:) forControlEvents:UIControlEventTouchUpInside];
    [_gaiKuanButton addTarget:self action:@selector(serviceTypeClick:) forControlEvents:UIControlEventTouchUpInside];
    [_gaiShouCunButton addTarget:self action:@selector(serviceTypeClick:) forControlEvents:UIControlEventTouchUpInside];
    [_fanXinButton addTarget:self action:@selector(serviceTypeClick:) forControlEvents:UIControlEventTouchUpInside];
    
   // [_];

}
-(void)selectGuideBtnClick:(UIButton *)sender
{
           if (addServiceIsOpen) {
            _resultGuideListViewContainer.hidden=YES;
            [UIView animateWithDuration:0.5 animations:^{
                
                UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
                [_resultGuideListArrowImage setImage:closeImage];
                CGRect frame=_resultGuideListViewContainer.frame;
                
                frame.size.height=1;
                [_resultGuideListViewContainer setFrame:frame];
                
            } completion:^(BOOL finished){
                addServiceIsOpen=NO;
            }];
            
        }
        else
        {
            [self requestGuideList];
            _resultGuideListViewContainer.hidden=NO;
            [UIView animateWithDuration:0.5 animations:^{
                UIImage *closeImage=[UIImage imageNamed:@"jiantou_upward.png"];
                
                
                [_resultGuideListArrowImage setImage:closeImage];
                CGRect frame=_resultGuideListViewContainer.frame;
                
                frame.size.height=657;
                [_resultGuideListViewContainer setFrame:frame];
                
            } completion:^(BOOL finished){
                addServiceIsOpen=YES;
            }];
            
        }
        
    
}
-(void)requestGuideList
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [HttpRequest requestData:@"Guide/GuideList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    [guideCodeArray removeAllObjects];
                    [guideNameArray removeAllObjects];
                    NSMutableArray  *mGuidesArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    for (int i=0; i<mGuidesArray.count; i++) {
                        [guideCodeArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"UserCode"]];
                        [guideNameArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"UserName"]];
                    }
                    // NSLog(@"guideCodeArray==%@",guideCodeArray);
                    //
                    
                    [_resultGuideListTableView reloadData];
                   
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}

-(void)updateLabel:(UITextField *)sender
{
    _resultTotalValue.text=sender.text;
}
-(void)serviceTypeClick:(UIButton *)button
{
    
    for (int i=0; i<6; i++) {
        UIImageView *img=(UIImageView *)[self.view viewWithTag:2000+i];
        [img setImage:[UIImage imageNamed:@"0000.png"]];
    
    }
    if(button.tag==1000)
    {
        serviceTypeStr=@"C";
    }
    else if (button.tag==1001)
    {
        serviceTypeStr=@"S";
    }
    else if(button.tag==1002)
    {
        serviceTypeStr=@"R";
    }
    else if(button.tag==1003)
    {
        serviceTypeStr=@"G";
    }
    else if(button.tag==1004)
    {
        serviceTypeStr=@"K";
    }
    else if(button.tag==1004)
    {
        serviceTypeStr=@"K";
    }
               UIImageView *img=(UIImageView *)[self.view viewWithTag:1000+button.tag];
    [img setImage:[UIImage imageNamed:@"1111.png"] ];
    
    
}

-(void)initServiceListView
{
    _searchTextField.text=@"";
   serviceNumArray=[NSMutableArray array];
   serviceStatusArray=[NSMutableArray array];
   serviceNumberArray=[NSMutableArray array];
   serviceTypeArray=[NSMutableArray array];
   serviceGuideNameArray=[NSMutableArray array];
   serviceMemberNameArray=[NSMutableArray array];
   serviceDateArray=[NSMutableArray array];
   serviceProductNameArray=[NSMutableArray array];
   servicePriceArray=[NSMutableArray array];
   serviceWeightArray=[NSMutableArray array];
    
  
}
-(void)initCashierViewContainer
{
   
    FPNumberPadView *numberPadView4 = [[FPNumberPadView alloc] initWithFrame:CGRectMake(0, 0, 948, 340)];
    numberPadView4.FPNumberPaddelegate=self;
    numberPadView4.textField = _serviceMoneyTextField;
    
    
   
    guideNameArray=[NSMutableArray array];
    guideCodeArray=[NSMutableArray array];
    
//    cashierGuideNameArray=[NSMutableArray array];
//    cashierGuideCodeArray=[NSMutableArray array];
    
    
    memberCodeStr=@"";
    guideCodeStr=@"";
    isOpened=NO;
    

}

-(void)initServiceDetailView
{
    serviceDetailProductNameArray=[NSMutableArray array];
    serviceDetailProductPriceArray=[NSMutableArray array];
    serviceDetailProductUrlArray=[NSMutableArray array];
    serviceDetailWeightArray=[NSMutableArray array];
    serviceDetailAttributeArray=[NSMutableArray array];
    serviceDetailProductAddressArray=[NSMutableArray array];
    serviceDetailCodeArray=[NSMutableArray array];
    CGRect viewFrame1=_serviceDetailView.frame;
    viewFrame1.origin.y=768;
    _serviceDetailView.frame=viewFrame1;
    
    [_serviceDetailAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_serviceDetailAlphaView addTarget:self action:@selector(serviceDetailAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];

}
-(void)resultAlphaViewClick
{
    [_searchTextField resignFirstResponder];
      // [_chengSeTextField resignFirstResponder];
  
    [_searchProductTextField resignFirstResponder];
   
    [_serviceMoneyTextField resignFirstResponder];
   
    [_resultTextView resignFirstResponder];

    [_resultScrollView setContentOffset:CGPointMake(0, 0)];
    
    [UIView animateWithDuration:0.3 animations:^{
        CGRect viewFrame=_resultScrollView.frame;
        viewFrame.origin.y=0;
        _resultScrollView.frame=viewFrame;
    } completion:^(BOOL finished){
        
    }];

    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_addServiceSearchResultViewContainer.frame;
         viewFrame.origin.y=768;
         _addServiceSearchResultViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         CGRect viewFrame1=_addServiceViewContainer.frame;
         viewFrame1.origin.y=768;
         _addServiceViewContainer.frame=viewFrame1;
         CGRect viewFrame=_addServiceSearchProductViewContainer.frame;
         viewFrame.origin.y=768;
         _addServiceSearchProductViewContainer.frame=viewFrame;
         
     }];

}
-(void)searchProductAlphaViewClick
{
    [_searchTextField resignFirstResponder];
    [_searchProductTextField resignFirstResponder];
    [_serviceMoneyTextField resignFirstResponder];

    [_resultTextView resignFirstResponder];

    CGRect viewFrame=_addServiceViewContainer.frame;
    viewFrame.origin.y=0;
    _addServiceViewContainer.frame=viewFrame;
    
    CGRect frame=_addServiceSearchProductViewContainer.frame;
    
    frame.origin.y=768;
    [_addServiceSearchProductViewContainer setFrame:frame];

    
    
//    [UIView animateWithDuration:0.5f animations:^
//     {
         CGRect frame0=_addServiceSearchResultViewContainer.frame;
         
         frame0.origin.y=0;
         [_addServiceSearchResultViewContainer setFrame:frame0];

//     }completion:^(BOOL finished) {
//         
//     }];

}
-(void)serviceDetailAlphaViewClick
{
    [_searchTextField resignFirstResponder];
   
    [_searchProductTextField resignFirstResponder];
   
    [_serviceMoneyTextField resignFirstResponder];
    
    [_resultTextView resignFirstResponder];
  

    [_detailScrollView setContentOffset:CGPointMake(0, 0)];
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_serviceDetailView.frame;
         viewFrame.origin.y=768;
         _serviceDetailView.frame=viewFrame;
     }completion:^(BOOL finished) {
         
     }];
    
}
-(void)addServiceButtonClick
{
    [_searchTextField resignFirstResponder];
   // NSLog(@"33333333");
    for (int i=0; i<6; i++) {
        UIImageView *img=(UIImageView *)[self.view viewWithTag:2000+i];
        [img setImage:[UIImage imageNamed:@"0000.png"]];
        
    }
    _resultGradeLabel.hidden=YES;
    _resultGradeTagLabel.hidden=YES;
    _resultSexImg.hidden=YES;
    _resultMemberNameAndPhoneLabel.hidden=YES;
    _resultMemberNameAndPhoneLabel.text=@"";
    _memberNoteLabel.hidden=NO;
    selectMemberCodeStr=@"";
    
    serviceTypeStr=@"";
    guideCodeStr=[Global getGuideCodeStr];
       _serviceMoneyTextField.text=@"";
    _resultGuideNameLabel.text=[Global getGuideNameStr];
    
    [Global resizeForLable:_resultGuideNameLabel WithText:_resultGuideNameLabel.text parentView:self.view];
    CGRect frameK=_resultGuideNameLabel.frame;
    frameK.origin.x=_resultGuideListArrowImage.frame.origin.x-frameK.size.width-5;
    _resultGuideNameLabel.frame=frameK;


    _serviceMoneyTextField
    .text=@"";
    _resultTotalValue.text=@"";
    _searchProductTextField.text=@"";
    _searchTotalLabel.text=@"共有0个结果";
    _resultNoteView.hidden=NO;
    _resultTextView.text=@"";
    _resultTextViewImage.hidden=NO;
    _resultTextViewLabel.hidden=NO;
//    CGRect noteFrame=_resultNoteView.frame;
//    noteFrame.origin.y=190;
//    _resultNoteView.frame=noteFrame;
    [findProductImageArray removeAllObjects];
    [findMemberNameArray removeAllObjects];
    [findMemberCodeArray removeAllObjects ];
    [findMemberPhoneArray removeAllObjects];
    [findMemberGradeArray removeAllObjects];
    [findMemberSexArray removeAllObjects];
    // findProductURLArray=[NSMutableArray array];
    findProductCodeArray=[NSMutableArray array];
    [findProductNameArray removeAllObjects];
    [findProductPriceArray removeAllObjects];
    // findmProducts=[NSMutableArray array];
    [findProductWeightArray removeAllObjects];
     [findProductAddressArray removeAllObjects];
    [findProductDateArray removeAllObjects];
    [_searchProductTableView reloadData];
    
    [selectedProductImageArray removeAllObjects];
    [selectedProductAddressArray removeAllObjects];
    [selectedProductWeightArray removeAllObjects];
    [selectedProductPriceArray removeAllObjects];
    [selectedProductNameArray removeAllObjects];
    // NSMutableArray *selectedStatusArray;
    [selectedProductCodeArray removeAllObjects];
    [_resultTableView reloadData];
    
    CGRect frame3=_resultTableView.frame;
    frame3.size.height=120;
    _resultTableView.frame=frame3;
   
    CGRect frame2=_resultView.frame;
    frame2.origin.y=280;
    _resultView.frame=frame2;
    
//    CGRect frame0=_lastView.frame;
//    frame0.origin.y=701;
//    _lastView.frame=frame0;
   
    [_resultScrollView setContentSize:CGSizeMake(0, _resultView.frame.origin.y+ _resultView.frame.size.height+25)];
    [_resultScrollView setScrollEnabled:YES];


    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_addServiceViewContainer.frame;
         viewFrame.origin.y=0;
         _addServiceViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         
     }];
    
    
   
        CGRect frame=_addServiceSearchResultViewContainer.frame;
        
        frame.origin.y=0;
        [_addServiceSearchResultViewContainer setFrame:frame];
        
       CGRect frame1=_addServiceSearchProductViewContainer.frame;
    
    frame1.origin.y=768;
    [_addServiceSearchProductViewContainer setFrame:frame1];


}
-(void)deductiblePaymentBtnClick
{
    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"服务不支持抵扣支付" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
    [alert show];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;{
    // the user clicked OK
    if (alertView.tag==1000) {
        
        if (buttonIndex == 0)
        {
            if ([Global getLoginToken].length>0) {
                [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
                NSMutableArray *mDocumentLine=[NSMutableArray array];
                //        NSLog(@"findSkuAllCountArray===%@",findSkuAllCountArray);
                for (int i=0; i<selectedProductCodeArray.count; i++) {
                    NSString *codeTitle =[selectedProductCodeArray objectAtIndex:i];
                    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                    //    NSLog(@"codeContentssss==%@",codeContent);
                    [dic setValue:codeTitle forKey:@"ItemCode"];
                    [mDocumentLine addObject:dic];
                }
                
                NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
                [params setObject:[Global getLoginToken] forKey:@"Token"];
                // [params setObject:[guideCodeArray objectAtIndex:searchGuideCellTag] forKey:@"GuideCode"];
                [params setObject:guideCodeStr forKey:@"GuideCode"];
                
                [params setObject:_resultTextView.text forKey:@"Content"];
                [params setObject:_serviceMoneyTextField.text forKey:@"DocTotal"];
                [params setObject:serviceTypeStr forKey:@"DocType"];
                [params setObject:mDocumentLine forKey:@"DataLine"];
                 // NSLog(@"productStockPARAM===%@",params);
                [HttpRequest requestData:@"Guide/DService" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                    // [Global hideProgressHUDInternal:self.view];
                    if (isSuccess) {
                        if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                            [Global hideProgressHUDInternal:self.view];
                            // NSLog(@"ttttttttt===%@",severDataDict.dataDict);
                            NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                            [Global showTextHudSub:requestResultStr view:self.view];
                            
                            for (int i=0; i<6; i++) {
                                UIImageView *img=(UIImageView *)[self.view viewWithTag:2000+i];
                                [img setImage:[UIImage imageNamed:@"0000.png"]];
                                
                            }
                            guideCodeStr=@"";
                            _resultGuideNameLabel.text=@"";
                            
                            //                    [UIView animateWithDuration:0.5f animations:^
                            //                     {
                            CGRect viewFrame1=_addServiceViewContainer.frame;
                            viewFrame1.origin.y=768;
                            _addServiceViewContainer.frame=viewFrame1;
                            CGRect viewFrame0=_addServiceSearchProductViewContainer.frame;
                            viewFrame0.origin.y=768;
                            _addServiceSearchProductViewContainer.frame=viewFrame0;
                            CGRect viewFrame=_addServiceSearchResultViewContainer.frame;
                            viewFrame.origin.y=768;
                            _addServiceSearchResultViewContainer.frame=viewFrame;
                            //                     }completion:^(BOOL finished) {
                            //
                            //                     }];
                            
                            [serviceNumArray removeAllObjects];
                            [serviceTypeArray removeAllObjects];
                            [serviceStatusArray removeAllObjects];
                            [serviceNumberArray removeAllObjects];
                            [serviceGuideNameArray removeAllObjects];
                            [serviceMemberNameArray removeAllObjects];
                            [serviceDateArray removeAllObjects];
                            [serviceProductNameArray removeAllObjects];
                            [servicePriceArray removeAllObjects];
                            [serviceWeightArray removeAllObjects];
                            _PageIndex=0;
                            [self loadServiceListNextPage:_PageIndex];
                            if ([_serviceMoneyTextField.text floatValue]>0) {
                                CGRect viewFrame1=_addServiceViewContainer.frame;
                                viewFrame1.origin.y=768;
                                _addServiceViewContainer.frame=viewFrame1;
                                if (cashierVC.view!=nil) {
                                    
                                    [cashierVC removeFromParentViewController];
                                    [cashierVC.view removeFromSuperview];
                                    
                                }
                                cashierVC=[[CashierViewController alloc] init];
                                cashierVC.delegate=self;
                                cashierVC.docTypeStr=@"Service";
                                cashierVC.docNumStr=[severDataDict.dataDict objectForKey:@"DocNum"] ;
                                cashierVC.view.frame = CGRectMake(0,
                                                                  0,
                                                                  self.view.bounds.size.width,
                                                                  self.view.bounds.size.height);
                                
                                [self addChildViewController:cashierVC];
                                [self.view addSubview:cashierVC.view];
                                
                                
                                guideCodeStr=[severDataDict.dataDict objectForKey:@"GuideCode"];
                                
                                
                                
                                
                            }
                            
                        }
                        else
                        {
                            [Global hideProgressHUDInternal:self.view];
                            NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                            //  [Global showTextHud:requestResultStr view:self.view];
                            [Global showTextHudSub:requestResultStr view:self.view];
                            
                            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                                
                                if (_timer!=nil) {
                                    [_timer invalidate];
                                    _timer=nil;
                                }
                                [Global loginViewController:self noteStr:requestResultStr];
                                //  [Global loginViewController:self];
                            }
                            
                        }
                    }
                    else
                    {
                        [Global hideProgressHUDInternal:self.view];
                        [Global showTextHudSub:@"连接失败" view:self.view];
                    }
                }];
                
            }

            
        }
    }
}
-(IBAction)addServiceScanBtnClick :(id)sender
{
    if (commonScanVC.view!=nil) {
        
        [commonScanVC removeFromParentViewController];
        [commonScanVC.view removeFromSuperview];
        
    }
    commonScanVC=[[CommonScanViewController alloc] init];
    commonScanVC.delegate=self;
   
    commonScanVC.view.frame = CGRectMake(0,
                                      0,
                                      self.view.bounds.size.width,
                                      self.view.bounds.size.height);
    
    [self addChildViewController:commonScanVC];
    [self.view addSubview:commonScanVC.view];

}
-(void)CommonScanResult:(NSString *)codeStr
{
    //NSLog(@"codeStr=====%@",codeStr);
    if (commonScanVC.view!=nil) {
      //   NSLog(@"dddddddd");
        [commonScanVC removeFromParentViewController];
        [commonScanVC.view removeFromSuperview];
        
    }
    [self findScan:codeStr];

}
-(void)findScan:(NSString *)keyWord
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:keyWord forKey:@"KeyWord"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:1];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:0];
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
        [params setObject:@"Service" forKey:@"BType"];
        [HttpRequest requestData:@"Product/GetPItemList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    _searchNoteView.hidden=YES;
                    // NSLog(@"findProductList/////=%@",severDataDict.dataDict);
                   
                    NSMutableArray  *findmProducts=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    if (findmProducts.count>0) {
                        
                   
                    NSString *memberCodeString=[[findmProducts objectAtIndex:0] objectForKey:@"MemberCode"];
                     if ([memberCodeString isEqualToString:selectMemberCodeStr]||selectMemberCodeStr.length==0) {
                        selectMemberCodeStr=[[findmProducts objectAtIndex:0] objectForKey:@"MemberCode"];
                         
                         _resultMemberNameAndPhoneLabel.hidden=NO;
                         _resultSexImg.hidden=NO;
                         _resultGradeTagLabel.hidden=NO;
                         _resultGradeLabel.hidden=NO;
                         _resultNoteView.hidden=YES;
                         
                         _resultMemberNameAndPhoneLabel.text=[NSString stringWithFormat:@"(%@ %@)",[[findmProducts objectAtIndex:0] objectForKey:@"MemberName"],[[findmProducts objectAtIndex:0] objectForKey:@"Phone"]];
                         // [self resizeLabel:_resultMemberNameAndPhoneLabel];
                         [Global resizeForLable:_resultMemberNameAndPhoneLabel WithText:_resultMemberNameAndPhoneLabel.text parentView:self.view];
                         if([memberCodeString length]>0)
                         {
                             _memberNoteLabel.hidden=YES;
                             
                         }
                         else
                         {
                             _memberNoteLabel.hidden=NO;
                         }
                         CGRect frame4=_resultSexImg.frame;
                         frame4.origin.x=_resultMemberNameAndPhoneLabel.frame.origin.x+_resultMemberNameAndPhoneLabel.frame.size.width;
                         _resultSexImg.frame=frame4;
                         
                         CGRect frame6=_resultGradeTagLabel.frame;
                         frame6.origin.x=_resultSexImg.frame.origin.x+_resultSexImg.frame.size.width+10;
                         _resultGradeTagLabel.frame=frame6;
                         
                         CGRect frame5=_resultGradeLabel.frame;
                         frame5.origin.x=_resultGradeTagLabel.frame.origin.x+_resultGradeTagLabel.frame.size.width+3;
                         _resultGradeLabel.frame=frame5;
                         
                         NSString *memberGradeStr=[[findmProducts objectAtIndex:0] objectForKey:@"Grade"];
                         if ([memberGradeStr length]>0) {
                             _resultGradeLabel.text=[[findmProducts objectAtIndex:0] objectForKey:@"Grade"];
                             // [self resizeLabel:_resultGradeLabel];
                             [Global resizeForLable:_resultGradeLabel WithText:_resultGradeLabel.text parentView:self.view];
                         }
                         else
                         {
                             _resultGradeLabel.hidden=YES;
                             _resultGradeTagLabel.hidden=YES;
                         }
                         
                         NSString *sexString=[[findmProducts objectAtIndex:0] objectForKey:@"Sex"];
                         if ([sexString isEqualToString:@"男"]) {
                             [_resultSexImg setImage:[UIImage imageNamed:@"nan_.png"]];
                         }
                         else if ([ sexString isEqualToString:@"女"])
                         {
                             [_resultSexImg setImage:[UIImage imageNamed:@"nv_.png"]];
                         }
                         else
                         {
                             _resultSexImg.hidden=YES;
                         }
                         
                         NSString *productCodeString=[[findmProducts objectAtIndex:0] objectForKey:@"ItemCode"];
                     if (![selectedProductCodeArray containsObject:productCodeString]) {
                    for (int i=0; i<findmProducts.count; i++) {
                        [selectedProductImageArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"ImageUrl"]];
                        [selectedProductCodeArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"ItemCode"]];
                        [selectedProductNameArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"ItemName"]];
                        [selectedProductPriceArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"Price"]];
                        [selectedProductWeightArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"Gram"]];
                        [selectedProductAddressArray  addObject:[[findmProducts objectAtIndex:i] objectForKey:@"MemberName"]];
                       // [findProductDateArray  addObject:[[findmProducts objectAtIndex:i] objectForKey:@"DocDate"]];
                         }
                         CGRect frame1=_resultTableView.frame;
                         frame1.size.height=120*selectedProductCodeArray.count;
                         _resultTableView.frame=frame1;
                         
                         [_resultTableView  reloadData];
                         CGRect frame2=_resultView.frame;
                         frame2.origin.y=_resultTableView.frame.origin.y+_resultTableView.frame.size.height;
                         _resultView.frame=frame2;
                         [_resultScrollView setContentSize:CGSizeMake(0, _resultView.frame.origin.y+ _resultView.frame.size.height+25)];
                         [_resultScrollView setScrollEnabled:YES];
                         
                         
                         CGRect viewFrame1=_addServiceViewContainer.frame;
                         viewFrame1.origin.y=0;
                         _addServiceViewContainer.frame=viewFrame1;
                         CGRect frame0=_addServiceSearchResultViewContainer.frame;
                         
                         frame0.origin.y=0;
                         [_addServiceSearchResultViewContainer setFrame:frame0];
                         
                         //  [UIView animateWithDuration:0.5 animations:^{
                         
                         UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
                         [_resultGuideListArrowImage setImage:closeImage];
                         
                         // } completion:^(BOOL finished){
                         addServiceIsOpen=NO;
                         //}];

                       }
                    }
                     else
                     {
                         UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择同一会员进行服务" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                         [alert show];
                         
                     }
                    }
                    else
                    {
                        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"未找到该产品的服务信息" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                        [alert show];
                    }

                 //   [_searchProductTableView reloadData];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        
                        if (_timer!=nil) {
                            [_timer invalidate];
                            _timer=nil;
                        }
                        [Global loginViewController:self noteStr:requestResultStr];
                        //   [Global loginViewController:self];
                    }
                    
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}


-(IBAction)submitServiceClick:(id)sender
{
    if (serviceTypeStr.length>0&&selectedProductCodeArray.count>0) {
        if ([Global getLoginToken].length>0) {
            [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
            NSMutableArray *mDocumentLine=[NSMutableArray array];
            //        NSLog(@"findSkuAllCountArray===%@",findSkuAllCountArray);
            for (int i=0; i<selectedProductCodeArray.count; i++) {
                NSString *codeTitle =[selectedProductCodeArray objectAtIndex:i];
                NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                //    NSLog(@"codeContentssss==%@",codeContent);
                [dic setValue:codeTitle forKey:@"ItemCode"];
                [mDocumentLine addObject:dic];
            }
            
            NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
            [params setObject:[Global getLoginToken] forKey:@"Token"];
            // [params setObject:[guideCodeArray objectAtIndex:searchGuideCellTag] forKey:@"GuideCode"];
            [params setObject:guideCodeStr forKey:@"GuideCode"];
            
            [params setObject:_resultTextView.text forKey:@"Content"];
            [params setObject:_serviceMoneyTextField.text forKey:@"DocTotal"];
            [params setObject:serviceTypeStr forKey:@"DocType"];
            [params setObject:mDocumentLine forKey:@"DataLine"];
            //  NSLog(@"productStockPARAM===%@",params);
            [HttpRequest requestData:@"Guide/DService" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                // [Global hideProgressHUDInternal:self.view];
                if (isSuccess) {
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];
                        // NSLog(@"ttttttttt===%@",severDataDict.dataDict);
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global showTextHudSub:requestResultStr view:self.view];
                        
                        for (int i=0; i<6; i++) {
                            UIImageView *img=(UIImageView *)[self.view viewWithTag:2000+i];
                            [img setImage:[UIImage imageNamed:@"0000.png"]];
                            
                        }
                        guideCodeStr=@"";
                        _resultGuideNameLabel.text=@"";
                        
                        //                    [UIView animateWithDuration:0.5f animations:^
                        //                     {
                        CGRect viewFrame1=_addServiceViewContainer.frame;
                        viewFrame1.origin.y=768;
                        _addServiceViewContainer.frame=viewFrame1;
                        CGRect viewFrame0=_addServiceSearchProductViewContainer.frame;
                        viewFrame0.origin.y=768;
                        _addServiceSearchProductViewContainer.frame=viewFrame0;
                        CGRect viewFrame=_addServiceSearchResultViewContainer.frame;
                        viewFrame.origin.y=768;
                        _addServiceSearchResultViewContainer.frame=viewFrame;
                        //                     }completion:^(BOOL finished) {
                        //
                        //                     }];
                        
                        [serviceNumArray removeAllObjects];
                        [serviceTypeArray removeAllObjects];
                        [serviceStatusArray removeAllObjects];
                        [serviceNumberArray removeAllObjects];
                        [serviceGuideNameArray removeAllObjects];
                        [serviceMemberNameArray removeAllObjects];
                        [serviceDateArray removeAllObjects];
                        [serviceProductNameArray removeAllObjects];
                        [servicePriceArray removeAllObjects];
                        [serviceWeightArray removeAllObjects];
                        _PageIndex=0;
                        [self loadServiceListNextPage:_PageIndex];
                        if ([_serviceMoneyTextField.text floatValue]>0) {
                            CGRect viewFrame1=_addServiceViewContainer.frame;
                            viewFrame1.origin.y=768;
                            _addServiceViewContainer.frame=viewFrame1;
                            if (cashierVC.view!=nil) {
                                
                                [cashierVC removeFromParentViewController];
                                [cashierVC.view removeFromSuperview];
                                
                            }
                            cashierVC=[[CashierViewController alloc] init];
                            cashierVC.delegate=self;
                            cashierVC.docTypeStr=@"Service";
                            cashierVC.docNumStr=[severDataDict.dataDict objectForKey:@"DocNum"] ;
                            cashierVC.view.frame = CGRectMake(0,
                                                              0,
                                                              self.view.bounds.size.width,
                                                              self.view.bounds.size.height);
                            
                            [self addChildViewController:cashierVC];
                            [self.view addSubview:cashierVC.view];
                            
                            
                            guideCodeStr=[severDataDict.dataDict objectForKey:@"GuideCode"];
                            
                            
                            
                            
                        }
                        
                    }
                    else
                    {
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        //  [Global showTextHud:requestResultStr view:self.view];
                        [Global showTextHudSub:requestResultStr view:self.view];
                        
                        if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                            
                            if (_timer!=nil) {
                                [_timer invalidate];
                                _timer=nil;
                            }
                            [Global loginViewController:self noteStr:requestResultStr];
                            //  [Global loginViewController:self];
                        }
                        
                    }
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
            }];
            
        }

        }
    else
    {
       if (serviceTypeStr.length==0)
        {
            
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择服务类型" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
            
        }
        else if (selectedProductCodeArray.count==0)
         {
             UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"当前服务产品无编码" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:@"取消",nil];
             alert.delegate=self;
             alert.tag=1000;
             [alert show];

         }

        
    }

}
-(IBAction)printBtnClick:(id)sender
{
    if (printWebVC.view!=nil) {
        [printWebVC.view removeFromSuperview];
        [printWebVC removeFromParentViewController];
        
    }
    printWebVC=[[PrintWebViewController alloc] init];
  //  printWebVC.delegate=self;
    printWebVC.docNumStr=_serviceDetailServiceNumLabel.text;
    printWebVC.docTypeStr=@"Service";
    printWebVC.docStatusStr=@"";
    printWebVC.view.frame = CGRectMake(0,
                                       0,
                                       self.view.bounds.size.width,
                                       self.view.bounds.size.height);
    
    [self addChildViewController:printWebVC];
    [self.view addSubview:printWebVC.view];
    
    
}
-(void) loadServiceListNextPage:(NSUInteger)oldPageNum {
    if(oldPageNum!=0 && _TotalCount<=serviceNumArray.count)
        return;
    if(oldPageNum == 0){
        [serviceNumArray removeAllObjects];
        [_serviceListTableView reloadData];
    }
    _PageIndex=oldPageNum+1;
    [self requestServiceList: _PageIndex pageSize:7];
}
-(void)requestServiceList:(NSUInteger)pageIndex pageSize:(NSUInteger)pageSize
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:pageSize];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:pageIndex];
        //        NSString *pageSizeStr=[NSString stringWithFormat:@"%d",pageSize];
        //        NSString *pageIndexStr=[NSString stringWithFormat:@"%d",pageIndex];
        
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
        [params setObject:_searchTextField.text forKey:@"KeyWord"];
        NSMutableArray *mDocumentLine=[NSMutableArray array];
        for (int i=0; i<filterTypeCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            //    NSLog(@"codeContentssss==%@",codeContent);
            [dic setValue:[filterTypeCodeArray objectAtIndex:i] forKey:@"FilterTypeCode"];
            //  NSLog(@"countContentssss==%@",countContent);
            [dic setValue:[selectFilterCodeArray objectAtIndex:i] forKey:@"FilterCode"];
            [mDocumentLine addObject:dic];
            
        }
        NSMutableArray *mDocumentLine1=[NSMutableArray array];
        for (int i=0; i<customTimeFilterTypeCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            //    NSLog(@"codeContentssss==%@",codeContent);
            [dic setValue:[customTimeFilterTypeCodeArray objectAtIndex:i] forKey:@"FilterTypeCode"];
            //  NSLog(@"countContentssss==%@",countContent);
            [dic setValue:startTimeStr forKey:@"Value1"];
            [dic setValue:endTimeStr forKey:@"Value2"];
            [mDocumentLine1 addObject:dic];
            
        }

        [params setObject:mDocumentLine forKey:@"DataLineFileterParam"];
        [params setObject:mDocumentLine1 forKey:@"DataLineFileterParam2"];
       //  NSLog(@"paramsLIST11111====%@",params);
        [HttpRequest requestData:@"Guide/ServiceList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                 //    NSLog(@"sevicelist===%@",severDataDict.dataDict);
                    
                    _TotalCount=[[severDataDict.dataDict objectForKey:@"TotalCount"] integerValue];
                    _serviceTotal.text=[NSString stringWithFormat:@"共%lu条记录",(unsigned long)_TotalCount];
                    if (_TotalCount%7!=0) {
                        _TotalPage=_TotalCount/7+1;
                    }
                    else if (_TotalCount%7==0)
                    {
                        _TotalPage=_TotalCount/7;
                    }
                    NSMutableArray *mServiceArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    
                    //     NSLog(@"mOrderArray===%@",mOrderArray);
                    if ( mServiceArray.count>0) {
                        for (int i=0; i< mServiceArray.count; i++) {
                            
                            [serviceNumArray addObject:[[mServiceArray objectAtIndex:i] objectForKey:@"DocNum"]];
                            [serviceTypeArray addObject:[[mServiceArray objectAtIndex:i] objectForKey:@"DocType"]];
                            [serviceStatusArray addObject:[[mServiceArray objectAtIndex:i] objectForKey:@"DocStatus"]];
                            [serviceNumberArray addObject:[[mServiceArray objectAtIndex:i] objectForKey:@"Number"]];
                            [serviceGuideNameArray addObject:[[mServiceArray objectAtIndex:i] objectForKey:@"GuideName"]];
                            [serviceMemberNameArray addObject:[[mServiceArray objectAtIndex:i] objectForKey:@"MemberName"]];
                            [serviceDateArray addObject:[[mServiceArray objectAtIndex:i] objectForKey:@"DocDate"]];
                            [serviceProductNameArray addObject:[[mServiceArray objectAtIndex:i] objectForKey:@"ItemName"]];
                            [servicePriceArray addObject:[[mServiceArray objectAtIndex:i] objectForKey:@"DocTotal"]];
                            [serviceWeightArray addObject:[[mServiceArray objectAtIndex:i] objectForKey:@"GramTotal"]];
                        }
                    }
                    
                    [_serviceListTableView reloadData];
                    
                   
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        
                        if (_timer!=nil) {
                            [_timer invalidate];
                            _timer=nil;
                        }
                      [Global loginViewController:self noteStr:requestResultStr];
                       // [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    if (_refreshHeaderView == nil) {
        EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - _serviceListTableView.bounds.size.height, self.view.frame.size.width, _serviceListTableView.bounds.size.height)];
        view.delegate = self;
        [_serviceListTableView addSubview:view];
        _refreshHeaderView = view;
        
        
    }
    
    //  update the last update date
    [_refreshHeaderView refreshLastUpdatedDate];

    // Do any additional setup after loading the view from its nib.
}
#pragma mark -
#pragma mark Data Source Loading / Reloading Methods

- (void)reloadTableViewDataSource{
    [serviceNumArray removeAllObjects];
    [serviceTypeArray removeAllObjects];
    [serviceStatusArray removeAllObjects];
    [serviceNumberArray removeAllObjects];
    [serviceGuideNameArray removeAllObjects];
    [serviceMemberNameArray removeAllObjects];
    [serviceDateArray removeAllObjects];
    [serviceProductNameArray removeAllObjects];
    [servicePriceArray removeAllObjects];
    [serviceWeightArray removeAllObjects];

    _PageIndex=0;
    [self loadServiceListNextPage:_PageIndex];
    //  should be calling your tableviews data source model to reload
    //  put here just for demo
    _reloading = YES;
    
}

- (void)doneLoadingTableViewData{
    
    //  model should call this when its done loading
    _reloading = NO;
    [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:_serviceListTableView];
    
}


#pragma mark -
#pragma mark UIScrollViewDelegate Methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
     if (scrollView==_serviceListTableView) {
    [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
     }
    
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    if (scrollView==_serviceListTableView) {
    [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
    }
}


#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate Methods

- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
    
    [self reloadTableViewDataSource];
    [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];
    
}

- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
    
    return _reloading; // should return if data source model is reloading
    
}

- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{
    
    return [NSDate date]; // should return date data source was last changed
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView==_serviceListTableView) {
        return serviceNumArray.count;
    }
    else if(tableView==_resultGuideListTableView)
    {
        return guideCodeArray.count;
    }
    else if (tableView==_serviceDetailTableView)
    {
        return serviceDetailProductNameArray.count;
    }
   else if (tableView==_searchProductTableView) {
        
        return findProductCodeArray.count;
    }
   else if (tableView==_resultTableView)
   {
       return selectedProductCodeArray.count;
   }

  
    return 1;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==_serviceListTableView||tableView==_serviceDetailTableView||tableView==_searchProductTableView||tableView==_resultTableView) {
        return 120;
    }
    else if(tableView==_resultGuideListTableView)
        return 60;
    
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView==_serviceListTableView) {
        static NSString * const  ServiceManagementIdentifier = @"ServiceManagementIdentifier";
        ServiceManagementTableViewCell *cell=( ServiceManagementTableViewCell *)[tableView dequeueReusableCellWithIdentifier: ServiceManagementIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"ServiceManagementTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
            cell.delegate=self;
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
//        cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0f];
        cell.piaoJuBuButton.tag=indexPath.row;
        cell.buShouYinButton.tag=indexPath.row;
        if (serviceNumArray.count>0) {
            cell.serviceNumLabel.text=[serviceNumArray objectAtIndex:indexPath.row];
          //  [self resizeLabel:cell.serviceNumLabel];
             [Global resizeForLable:cell.serviceNumLabel WithText:cell.serviceNumLabel.text parentView:self.view];
            CGRect frame=cell.serviceStatusLabel.frame;
            frame.origin.x=cell.serviceNumLabel.frame.origin.x+cell.serviceNumLabel.frame.size.width-5;
            cell.serviceStatusLabel.frame=frame;
            
            CGRect frame1=cell.serviceTypeLabel.frame;
            frame1.origin.x=cell.serviceStatusLabel.frame.origin.x+cell.serviceStatusLabel.frame.size.width+5;
            cell.serviceTypeLabel.frame=frame1;
        }
        if (serviceGuideNameArray.count>0) {
            NSString *guideNameStr=[serviceGuideNameArray objectAtIndex:indexPath.row];
            if (guideNameStr.length>0) {
                 cell.guideNameLabel.text=guideNameStr;
            }
            else
            {
            cell.guideNameLabel.text=@"未填写";
            }
           // [self resizeLabel:cell.guideNameLabel];
             [Global resizeForLable:cell.guideNameLabel WithText:cell.guideNameLabel.text parentView:self.view];
            CGRect frame=cell.memberNameTagLabel.frame;
            frame.origin.x=cell.guideNameLabel.frame.origin.x+cell.guideNameLabel.frame.size.width+15;
            cell.memberNameTagLabel.frame=frame;
        }

        if (serviceMemberNameArray.count>0) {
            
            NSString *memberNameStr=[serviceMemberNameArray objectAtIndex:indexPath.row];
            if (memberNameStr.length>0) {
                cell.memberNameLabel.text=memberNameStr;
            }
            else
            {
                cell.memberNameLabel.text=@"未填写";
            }
         //   [self resizeLabel:cell.memberNameLabel];
            [Global resizeForLable:cell.memberNameLabel WithText:cell.memberNameLabel.text parentView:self.view];
            CGRect frame=cell.memberNameLabel.frame;
            frame.origin.x=cell.memberNameTagLabel.frame.origin.x+cell.memberNameTagLabel.frame.size.width+3;
            cell.memberNameLabel.frame=frame;
            
            CGRect frame1=cell.dateTagLabel.frame;
            frame1.origin.x=cell.memberNameLabel.frame.origin.x+cell.memberNameLabel.frame.size.width+12;
            cell.dateTagLabel.frame=frame1;
            
            CGRect frame2=cell.dateLabel.frame;
            frame2.origin.x=cell.dateTagLabel.frame.origin.x+cell.dateTagLabel.frame.size.width+3;
            cell.dateLabel.frame=frame2;

        }
        if (serviceStatusArray.count>0) {
            NSString *statusStr=[serviceStatusArray objectAtIndex:indexPath.row];
            cell.serviceStatusLabel.text=[NSString stringWithFormat:@"【%@】",statusStr];
            if ([statusStr isEqualToString:@"已结算"]) {
                 [cell.serviceStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                cell.buShouYinButton.layer.borderColor=[[UIColor colorWithRed:245.0f/255.0f green:245.0f/255.0f blue:245.0f/255.0f alpha:1] CGColor];
                //  [cell.confirmArrivalBtn.];
                [cell.buShouYinButton setTitleColor:[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                //[cell.confirmArrivalBtn setTintColor:];
                [cell.buShouYinButton setUserInteractionEnabled:NO];
            }
            
            else
            {
                  [cell.serviceStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                
                cell.buShouYinButton.layer.borderColor=[[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1] CGColor];
                [cell.buShouYinButton setUserInteractionEnabled:YES];
                [cell.buShouYinButton setTitleColor:[UIColor colorWithRed:60.0f/255.0f green:60.0f/255.0f blue:60.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
            }

        }

        if (serviceTypeArray.count>0) {
            NSString *typeStr=[serviceTypeArray objectAtIndex:indexPath.row];
            cell.serviceTypeLabel.text=typeStr;
        }

               //  NSLog(@"memberContacts11111==%@",memberContacts);
        if (serviceDateArray.count>0) {
            cell.dateLabel.text=[serviceDateArray objectAtIndex:indexPath.row];
        }
        NSString *numberStr=@"";
        NSString *weightStr=@"";
        NSString *nameStr=@"";
        if (serviceNumberArray.count>0) {
            numberStr=[NSString stringWithFormat:@"%ld",(long)[[serviceNumberArray objectAtIndex:indexPath.row] integerValue]];
        }
        if (serviceWeightArray.count>0) {
            weightStr=[NSString stringWithFormat:@"%0.02f",[[serviceWeightArray objectAtIndex:indexPath.row] floatValue]];
        }

        if (serviceProductNameArray.count>0 ) {
             nameStr=[serviceProductNameArray objectAtIndex:indexPath.row];
            if ([numberStr floatValue]>1) {
                cell.productNameLabel.text=[NSString stringWithFormat:@"%@...  共%@件/%@g",nameStr,numberStr,weightStr];
            }
            else
            {
                cell.productNameLabel.text=[NSString stringWithFormat:@"%@  共%@件/%@g",nameStr,numberStr,weightStr];
            }

           // cell.productNameLabel.text=[NSString stringWithFormat:@"%@/%@",nameStr,weightStr];
            //[self resizeLabel:cell.productNameLabel];
            [Global resizeForLable:cell.productNameLabel WithText:cell.productNameLabel.text parentView:self.view];
            CGRect frame=cell.priceTagLabel.frame;
            frame.origin.x=cell.productNameLabel.frame.origin.x+cell.productNameLabel.frame.size.width+12;
            cell.priceTagLabel.frame=frame;
            
            CGRect frame1=cell.priceLabel.frame;
            frame1.origin.x=cell.priceTagLabel.frame.origin.x+cell.priceTagLabel.frame.size.width+3;
            cell.priceLabel.frame=frame1;
        }
              if (servicePriceArray.count>0) {
                  if ([servicePriceArray objectAtIndex:indexPath.row]!=[NSNull null]) {
                
                  float AvgPrice=[[servicePriceArray objectAtIndex:indexPath.row] floatValue];
                  NSString *AvgPriceStr=[Global floatConvertPercentile:AvgPrice];
            cell.priceLabel.text=[NSString stringWithFormat:@"¥%@",AvgPriceStr];
//                      if ([[servicePriceArray objectAtIndex:indexPath.row] floatValue]<=0) {
//                          cell.buShouYinButton.layer.borderColor=[[UIColor colorWithRed:245.0f/255.0f green:245.0f/255.0f blue:245.0f/255.0f alpha:1] CGColor];
//                          //  [cell.confirmArrivalBtn.];
//                          [cell.buShouYinButton setTitleColor:[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
//                          //[cell.confirmArrivalBtn setTintColor:];
//                          [cell.buShouYinButton setUserInteractionEnabled:NO];
//                      }
//                      else
//                      {
//                          cell.buShouYinButton.layer.borderColor=[[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1] CGColor];
//                          [cell.buShouYinButton setUserInteractionEnabled:YES];
//                          [cell.buShouYinButton setTitleColor:[UIColor colorWithRed:60.0f/255.0f green:60.0f/255.0f blue:60.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
//                          
//                      }
//
                  }
        }
        if (indexPath.row == [serviceNumArray count] - 1)
        {
            if (_PageIndex<=_TotalPage) {
                //  NSLog(@"###LOADING???");
                [self loadServiceListNextPage:_PageIndex];
            }
        }
        return cell;
    }
    
    else if (tableView==_resultGuideListTableView)
    {
        static NSString * const  GuideListIdentifier = @"GuideListCellIdentifier";
        GuideListTableViewCell *cell=( GuideListTableViewCell *)[tableView dequeueReusableCellWithIdentifier: GuideListIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"GuideListTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
//        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
//        cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0f];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (guideNameArray.count>0) {
            cell.guideNameLabel.text=[guideNameArray objectAtIndex:indexPath.row];
        }
        return cell;
        
    }
    else if (tableView==_resultTableView)
    {
        static NSString * const  ResultTableViewCellIdentifier = @"ResultTableViewCellIdentifier";
        ResultTableViewCell *cell=( ResultTableViewCell *)[tableView dequeueReusableCellWithIdentifier: ResultTableViewCellIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"ResultTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
//        cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0f];
        if (selectedProductImageArray.count>0) {
            
            if ([[selectedProductImageArray objectAtIndex:indexPath.row] length]>0) {
                
            [cell.resultProductImageView setImageWithURL:[NSURL URLWithString:[selectedProductImageArray objectAtIndex:indexPath.row]]];
            }
            else
            {
            [cell.resultProductImageView setImage:[UIImage imageNamed:@"zhanweitu_.png"]];
            }
        }
        if (selectedProductAddressArray.count>0) {
            cell.resultProductDateLabel.text=[selectedProductAddressArray objectAtIndex:indexPath.row];
        }

        if (selectedProductWeightArray.count>0) {
            cell.resultProductWeightLabel.text=[NSString stringWithFormat:@"%0.02fg",[[selectedProductWeightArray objectAtIndex:indexPath.row] floatValue]];
            cell.resultProductWeightLabel.numberOfLines = 0;
            cell.resultProductWeightLabel.lineBreakMode = NSLineBreakByWordWrapping;
            CGSize maximumLabelSize = CGSizeMake(1000, cell.resultProductWeightLabel.frame.size.height);
            
            CGSize expectSize = [cell.resultProductWeightLabel sizeThatFits:maximumLabelSize];
            CGRect frame1 = CGRectMake(cell.resultProductWeightLabel.frame.origin.x, cell.resultProductWeightLabel.frame.origin.y,expectSize.width, cell.resultProductWeightLabel.frame.size.height );
            cell.resultProductWeightLabel.frame=frame1;
            
            CGRect frame=cell.resultProductPriceLabel.frame;
            frame.origin.x=cell.resultProductWeightLabel.frame.origin.x+cell.resultProductWeightLabel.frame.size.width+12;
            cell.resultProductPriceLabel.frame=frame;
            
        }
        if (selectedProductPriceArray.count>0) {
            float AvgPrice=[[selectedProductPriceArray objectAtIndex:indexPath.row] floatValue];
            NSString *AvgPriceStr=[Global floatConvertPercentile:AvgPrice];
            cell.resultProductPriceLabel.text=[NSString stringWithFormat:@"¥%@",AvgPriceStr];
        }
        if (selectedProductNameArray.count>0) {
            cell.resultProductNameLabel.text=[NSString stringWithFormat:@"%@ %@",[selectedProductCodeArray objectAtIndex:indexPath.row],[selectedProductNameArray objectAtIndex:indexPath.row]];//[selectedProductNameArray objectAtIndex:indexPath.row];
        }
        cell.statusLabel.hidden=YES;
        cell.lineLabel.hidden=NO;
        if (indexPath.row==selectedProductCodeArray.count-1) {
            cell.lineLabel.hidden=YES;
        }
        
//        if (selectedStatusArray.count>0) {
//            cell.statusLabel.text=[selectedStatusArray objectAtIndex:indexPath.row];
//        }
        
//        if ([cell.statusLabel.text isEqualToString:@"退"] ) {
//            cell.resultProductDateLabel.hidden=NO;
//            cell.resultProductDateLabel1.hidden=NO;
//            if (selectedProductDateArray.count>0) {
//                cell.resultProductDateLabel.text=[selectedProductDateArray objectAtIndex:indexPath.row];
//            }
//            [cell.statusLabel setBackgroundColor:[UIColor colorWithRed:196.0f/255.0f green:102.0f/255.0f blue:58.0f/255.0f alpha:1.0]];
//        }
//        else if ([cell.statusLabel.text isEqualToString:@"换"] ) {
//            cell.resultProductDateLabel.hidden=YES;
//            cell.resultProductDateLabel1.hidden=YES;
//            [cell.statusLabel setBackgroundColor:[UIColor colorWithRed:201.0f/255.0f green:160.0f/255.0f blue:56.0f/255.0f alpha:1.0]];
//        }
//        
        
        
        return cell;
        
    }

    else if(tableView==_serviceDetailTableView)
    {
        static NSString * const  OrderDetailIdentifier = @"OrderDetailIdentifier";
        OrderDetailTableViewCell *cell=( OrderDetailTableViewCell *)[tableView dequeueReusableCellWithIdentifier: OrderDetailIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"OrderDetailTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
//        cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0f];
        if (serviceDetailProductNameArray.count>0) {
            cell.productNameLabel.text=[NSString stringWithFormat:@"%@ %@",[serviceDetailCodeArray objectAtIndex:indexPath.row],[serviceDetailProductNameArray objectAtIndex:indexPath.row]];//;
        }
        if (serviceDetailProductAddressArray.count>0) {
            cell.stockAddressLabel.text=[serviceDetailProductAddressArray objectAtIndex:indexPath.row];
        }
        if (serviceDetailProductUrlArray.count>0) {
            if ([[serviceDetailProductUrlArray objectAtIndex:indexPath.row] length]>0) {
                
           
            [cell.productImageView setImageWithURL:[NSURL URLWithString:[serviceDetailProductUrlArray objectAtIndex:indexPath.row]]];
            }
        }
        if (serviceDetailWeightArray.count>0) {
            
            cell.weightLabel.text=[NSString stringWithFormat:@"%0.02fg",[[serviceDetailWeightArray objectAtIndex:indexPath.row] floatValue]];
            cell.weightLabel.numberOfLines = 0;
            cell.weightLabel.lineBreakMode = NSLineBreakByWordWrapping;
            CGSize maximumLabelSize = CGSizeMake(1000, cell.weightLabel.frame.size.height);
            
            CGSize expectSize = [cell.weightLabel sizeThatFits:maximumLabelSize];
            CGRect frame1 = CGRectMake(cell.weightLabel.frame.origin.x, cell.weightLabel.frame.origin.y,expectSize.width, cell.weightLabel.frame.size.height );
            cell.weightLabel.frame=frame1;

            CGRect frame=cell.priceLabel.frame;
            frame.origin.x=cell.weightLabel.frame.origin.x+cell.weightLabel.frame.size.width+10;
            cell.priceLabel.frame=frame;
        }
        if (serviceDetailAttributeArray.count>0) {
            if ([serviceDetailAttributeArray objectAtIndex:indexPath.row]!=[NSNull null]) {
                cell.attributesLabel.text=[NSString stringWithFormat:@"%@",[serviceDetailAttributeArray objectAtIndex:indexPath.row]];
                
            }
            cell.attributesLabel.numberOfLines = 0;
            cell.attributesLabel.lineBreakMode = NSLineBreakByWordWrapping;
            CGSize maximumLabelSize = CGSizeMake(1000, cell.attributesLabel.frame.size.height);
            
            CGSize expectSize = [cell.attributesLabel sizeThatFits:maximumLabelSize];
            CGRect frame1 = CGRectMake(cell.attributesLabel.frame.origin.x, cell.attributesLabel.frame.origin.y,expectSize.width, cell.attributesLabel.frame.size.height );
            cell.attributesLabel.frame=frame1;
            
            // [self resizeLabel: cell.attributesLabel];
            
            CGRect frame= cell.weightTagLabel.frame;
            if ([[serviceDetailAttributeArray objectAtIndex:indexPath.row] length]>0) {
                
                frame.origin.x=cell.attributesLabel.frame.origin.x+cell.attributesLabel.frame.size.width+12;
            }
            else
            {
                frame.origin.x=cell.attributesLabel.frame.origin.x+cell.attributesLabel.frame.size.width;
            }
            cell.weightTagLabel.frame=frame;
            
            CGRect frame2= cell.weightLabel.frame;
            frame2.origin.x=cell.weightTagLabel.frame.origin.x+cell.weightTagLabel.frame.size.width+1;
            cell.weightLabel.frame=frame2;
            
            CGRect frame3= cell.priceLabel.frame;
            frame3.origin.x=cell.weightLabel.frame.origin.x+cell.weightLabel.frame.size.width+60;
            cell.priceLabel.frame=frame3;

            
        }


        if (serviceDetailProductPriceArray.count>0) {
           
            float AvgPrice=[[serviceDetailProductPriceArray objectAtIndex:indexPath.row] floatValue];
            NSString *AvgPriceStr=[Global floatConvertPercentile:AvgPrice];
            
            cell.priceLabel.text=[NSString stringWithFormat:@"¥%@",AvgPriceStr];

        }
               return cell;
        
    }
    
    if (tableView==_searchProductTableView) {
        static NSString * const  searchProductAndMemberIdentifier = @"searchProductAndMemberIdentifier";
        searchProductAndMemberTableViewCell *cell=( searchProductAndMemberTableViewCell *)[tableView dequeueReusableCellWithIdentifier: searchProductAndMemberIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"searchProductAndMemberTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
//        cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0f];
        if (findProductImageArray.count>0) {
            //  NSLog(@"findProductURLArray====%@",findProductURLArray);
            NSString *leftUrlStr=[findProductImageArray objectAtIndex:indexPath.row];//[findProductURLArray objectAtIndex:indexPath.row];
            if (leftUrlStr.length>0) {
          
            [cell.productImageView setImageWithURL:[NSURL URLWithString:leftUrlStr]];
            }
            else
            {
            [cell.productImageView setImage:[UIImage imageNamed:@"zhanweitu_.png"]];
            }
        }
        if (findProductPriceArray.count>0) {
            float AvgPrice=[[findProductPriceArray objectAtIndex:indexPath.row] floatValue];
            NSString *AvgPriceStr=[Global floatConvertPercentile:AvgPrice];

            [cell.productMarketPriceLabel setText:[NSString stringWithFormat:@"¥%@",AvgPriceStr]];
            
           // [self resizeLabel:cell.productMarketPriceLabel];
             [cell.productSalePriceLabel setText:[NSString stringWithFormat:@"¥%@",AvgPriceStr]];
            
            CGRect frame=cell.productSalePriceLabel.frame;
            frame.origin.x=595-cell.productSalePriceLabel.frame.size.width;
            cell.productSalePriceLabel.frame=frame;
        }
        if(findProductAddressArray.count>0 )
        {
            [cell.productAddressLabel setText:[findProductAddressArray objectAtIndex:indexPath.row]];
        }
        if(findProductWeightArray.count>0 )
        {
            [cell.productWeightLabel setText:[NSString stringWithFormat:@"%0.02fg",[[findProductWeightArray objectAtIndex:indexPath.row] floatValue]]];
           // [self resizeLabel:cell.productWeightLabel];
            cell.productWeightLabel.numberOfLines = 0;
            cell.productWeightLabel.lineBreakMode = NSLineBreakByWordWrapping;
            CGSize maximumLabelSize = CGSizeMake(1000, cell.productWeightLabel.frame.size.height);
            
            CGSize expectSize = [cell.productWeightLabel sizeThatFits:maximumLabelSize];
            CGRect frame0 = CGRectMake(cell.productWeightLabel.frame.origin.x, cell.productWeightLabel.frame.origin.y,expectSize.width, cell.productWeightLabel.frame.size.height );
            cell.productWeightLabel.frame=frame0;

            CGRect frame=cell.productMarketPriceTagLabel.frame;
            frame.origin.x=cell.productWeightLabel.frame.origin.x+cell.productWeightLabel.frame.size.width+12;
            cell.productMarketPriceTagLabel.frame=frame;
            
            CGRect frame1=cell.productMarketPriceLabel.frame;
            frame1.origin.x=cell.productMarketPriceTagLabel.frame.origin.x+cell.productMarketPriceTagLabel.frame.size.width+3;
            cell.productMarketPriceLabel.frame=frame1;

        }

        if (findProductNameArray.count>0) {
           // [cell.productNameLabel setText:[findProductNameArray objectAtIndex:indexPath.row]];
            cell.productNameLabel.text=[NSString stringWithFormat:@"%@ %@",[findProductCodeArray objectAtIndex:indexPath.row],[findProductNameArray objectAtIndex:indexPath.row]];
            
        }
        if (findMemberCodeArray.count>0) {
            cell.memberCodeLabel.text=[findMemberCodeArray objectAtIndex:indexPath.row];
            
          //  NSLog(@"cell.memberCodeLabel.text===%@",cell.memberCodeLabel.text);
           // [self resizeLabel:cell.memberCodeLabel];
            cell.memberCodeLabel.numberOfLines = 0;
            cell.memberCodeLabel.lineBreakMode = NSLineBreakByWordWrapping;
            CGSize maximumLabelSize = CGSizeMake(1000, cell.memberCodeLabel.frame.size.height);
            
            CGSize expectSize = [cell.memberCodeLabel sizeThatFits:maximumLabelSize];
            CGRect frame0 = CGRectMake(cell.memberCodeLabel.frame.origin.x, cell.memberCodeLabel.frame.origin.y,expectSize.width, cell.memberCodeLabel.frame.size.height );
            cell.memberCodeLabel.frame=frame0;

            CGRect frame=cell.memberNameTagLabel.frame;
            frame.origin.x=cell.memberCodeLabel.frame.origin.x+cell.memberCodeLabel.frame.size.width+12;
            cell.memberNameTagLabel.frame=frame;
            
            CGRect frame1=cell.memberNameLabel.frame;
            frame1.origin.x=cell.memberNameTagLabel.frame.origin.x+cell.memberNameTagLabel.frame.size.width+3;
            cell.memberNameLabel.frame=frame1;

        }
        if (findMemberNameArray.count>0) {
            cell.memberNameLabel.text=[findMemberNameArray objectAtIndex:indexPath.row];
        }
        if (indexPath.row == [findProductCodeArray count] - 1)
        {
            if (_productPageIndex<=_productTotalPage) {
                //  NSLog(@"###LOADING???");
                [self loadProductNextPage:_productPageIndex];
            }
        }

        return cell;
    }
      return nil;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==_serviceListTableView) {
        [serviceDetailProductAddressArray removeAllObjects];
        [serviceDetailProductNameArray removeAllObjects];
        [serviceDetailProductUrlArray removeAllObjects];
        [serviceDetailWeightArray removeAllObjects];
        [serviceDetailAttributeArray removeAllObjects];
        [serviceDetailProductPriceArray removeAllObjects];
        [serviceDetailCodeArray removeAllObjects];
         [self requestServiceDetail:[serviceNumArray objectAtIndex:indexPath.row]];
        [UIView animateWithDuration:0.5f animations:^
         {
             CGRect viewFrame=_serviceDetailView.frame;
             viewFrame.origin.y=0;
             _serviceDetailView.frame=viewFrame;
         }completion:^(BOOL finished) {
             
         }];

      
    }
    else if (tableView==_serviceDetailTableView)
    {
        _isLoad=@"Y";
        if (commonProductDetailVC.view!=nil) {
            
            [commonProductDetailVC removeFromParentViewController];
            [commonProductDetailVC.view removeFromSuperview];
            
        }
        commonProductDetailVC=[[CommonProductDetailViewController alloc] init];
        commonProductDetailVC.delegate=self;
        commonProductDetailVC.codeStr=[serviceDetailCodeArray objectAtIndex:indexPath.row];
        commonProductDetailVC.view.frame = CGRectMake(0,
                                                      0,
                                                      self.view.bounds.size.width,
                                                      self.view.bounds.size.height);
        
        [self addChildViewController:commonProductDetailVC];
        [self.view addSubview:commonProductDetailVC.view];

    }
        else if (tableView==_resultGuideListTableView)
     {
         guideCodeStr=[guideCodeArray objectAtIndex:indexPath.row];
         searchGuideCellTag=indexPath.row;
         _resultGuideListViewContainer.hidden=YES;
         [UIView animateWithDuration:0.5 animations:^{
             
             UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
             [_resultGuideListArrowImage setImage:closeImage];
             CGRect frame=_resultGuideListViewContainer.frame;
             
             frame.size.height=1;
             [_resultGuideListViewContainer setFrame:frame];
             
         } completion:^(BOOL finished){
             addServiceIsOpen=NO;
         }];
         _resultGuideNameLabel.text=[guideNameArray objectAtIndex:indexPath.row];
         [Global resizeForLable:_resultGuideNameLabel WithText:_resultGuideNameLabel.text parentView:self.view];
         CGRect frameK=_resultGuideNameLabel.frame;
         frameK.origin.x=_resultGuideListArrowImage.frame.origin.x-frameK.size.width-5;
         _resultGuideNameLabel.frame=frameK;
     }
 
    else if (tableView==_searchProductTableView)
    {
        if ([[findMemberCodeArray objectAtIndex:indexPath.row] isEqualToString:selectMemberCodeStr]||selectMemberCodeStr.length==0) {

        selectMemberCodeStr=[findMemberCodeArray objectAtIndex:indexPath.row];
            
        [_searchProductTextField resignFirstResponder];
        _resultMemberNameAndPhoneLabel.hidden=NO;
        _resultSexImg.hidden=NO;
        _resultGradeTagLabel.hidden=NO;
        _resultGradeLabel.hidden=NO;
        
        _resultNoteView.hidden=YES;
        searchProductCellTag=indexPath.row;
        _resultMemberNameAndPhoneLabel.text=[NSString stringWithFormat:@"(%@ %@)",[findMemberNameArray objectAtIndex:indexPath.row],[findMemberPhoneArray objectAtIndex:indexPath.row]];
       // [self resizeLabel:_resultMemberNameAndPhoneLabel];
         [Global resizeForLable:_resultMemberNameAndPhoneLabel WithText:_resultMemberNameAndPhoneLabel.text parentView:self.view];
            if([[findMemberCodeArray objectAtIndex:indexPath.row] length]>0)
            {
                _memberNoteLabel.hidden=YES;
                
            }
            else
            {
                  _memberNoteLabel.hidden=NO;
            }
        CGRect frame4=_resultSexImg.frame;
        frame4.origin.x=_resultMemberNameAndPhoneLabel.frame.origin.x+_resultMemberNameAndPhoneLabel.frame.size.width;
        _resultSexImg.frame=frame4;
        
        CGRect frame6=_resultGradeTagLabel.frame;
        frame6.origin.x=_resultSexImg.frame.origin.x+_resultSexImg.frame.size.width+10;
        _resultGradeTagLabel.frame=frame6;
        
        CGRect frame5=_resultGradeLabel.frame;
        frame5.origin.x=_resultGradeTagLabel.frame.origin.x+_resultGradeTagLabel.frame.size.width+3;
        _resultGradeLabel.frame=frame5;
            
        
        if ([[findMemberGradeArray objectAtIndex:indexPath.row] length]>0) {
            _resultGradeLabel.text=[findMemberGradeArray objectAtIndex:indexPath.row];
           // [self resizeLabel:_resultGradeLabel];
            [Global resizeForLable:_resultGradeLabel WithText:_resultGradeLabel.text parentView:self.view];
        }
        else
        {
            _resultGradeLabel.hidden=YES;
            _resultGradeTagLabel.hidden=YES;
        }
        
        
        if ([[findMemberSexArray objectAtIndex:indexPath.row]isEqualToString:@"男"]) {
            [_resultSexImg setImage:[UIImage imageNamed:@"nan_.png"]];
        }
        else if ([[findMemberSexArray objectAtIndex:indexPath.row]isEqualToString:@"女"])
        {
             [_resultSexImg setImage:[UIImage imageNamed:@"nv_.png"]];
        }
        else
        {
            _resultSexImg.hidden=YES;
        }
        
        if (![selectedProductCodeArray containsObject:[findProductCodeArray objectAtIndex:indexPath.row]]) {
            [selectedProductCodeArray addObject:[findProductCodeArray objectAtIndex:indexPath.row]];
            
            NSString *urlStr=[findProductImageArray objectAtIndex:indexPath.row];
            [selectedProductImageArray addObject:urlStr];
//            if ([_statusLabel.text isEqualToString:@"退"]) {
//                [selectedProductDateArray addObject:[findProductDateArray objectAtIndex:indexPath.row]];
//            }
            
            [selectedProductWeightArray addObject:[NSString stringWithFormat:@"%0.02fg",[[findProductWeightArray objectAtIndex:indexPath.row] floatValue]]];
            [selectedProductPriceArray addObject:[NSString stringWithFormat:@"%0.02f",[[findProductPriceArray objectAtIndex:indexPath.row] floatValue]]];
            [selectedProductNameArray addObject:[findProductNameArray objectAtIndex:indexPath.row]];
             [selectedProductAddressArray addObject:[findProductAddressArray objectAtIndex:indexPath.row]];
           // [selectedStatusArray addObject:_statusLabel.text];
        }
        CGRect frame1=_resultTableView.frame;
        frame1.size.height=120*selectedProductCodeArray.count;
        _resultTableView.frame=frame1;
        
        [_resultTableView  reloadData];
        CGRect frame2=_resultView.frame;
        frame2.origin.y=_resultTableView.frame.origin.y+_resultTableView.frame.size.height;
        _resultView.frame=frame2;
        [_resultScrollView setContentSize:CGSizeMake(0, _resultView.frame.origin.y+ _resultView.frame.size.height+25)];
        [_resultScrollView setScrollEnabled:YES];
      

        CGRect viewFrame1=_addServiceViewContainer.frame;
        viewFrame1.origin.y=0;
        _addServiceViewContainer.frame=viewFrame1;
        CGRect frame0=_addServiceSearchResultViewContainer.frame;
        
        frame0.origin.y=0;
        [_addServiceSearchResultViewContainer setFrame:frame0];

      //  [UIView animateWithDuration:0.5 animations:^{
            
            UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
            [_resultGuideListArrowImage setImage:closeImage];
            
       // } completion:^(BOOL finished){
            addServiceIsOpen=NO;
        //}];
        CGRect frame=_addServiceSearchProductViewContainer.frame;
        
        frame.origin.y=768;
        [_addServiceSearchProductViewContainer setFrame:frame];
        
        }
        else
        {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择同一会员进行服务" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
            
        }
    }
}
-(void)commonProductDetailShopCartClick
{
    if ([self.delegate respondsToSelector:@selector(ServiceShopCtarClick)]) {
        
        [self.delegate ServiceShopCtarClick];
    }
    
}

-(void)requestServiceDetail:(NSString *)codeStr
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
       // [params setObject:@"Order" forKey:@"DocType"];
        [params setObject:codeStr forKey:@"DocNum"];
        // NSLog(@"paramsLIST====%@",params);
        [HttpRequest requestData:@"Guide/ServiceDetail" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
          //  NSLog(@"detaillll=%@",severDataDict.dataDict);
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    _serviceDetailServiceNumLabel.text=[severDataDict.dataDict objectForKey:@"DocNum"];
                   // [self resizeLabel:_serviceDetailServiceNumLabel];
                    [Global resizeForLable:_serviceDetailServiceNumLabel WithText:_serviceDetailServiceNumLabel.text parentView:self.view];

                    if ([severDataDict.dataDict objectForKey:@"MemberName"]==[NSNull null]||[[severDataDict.dataDict objectForKey:@"MemberName"] length]==0) {
                         _serviceDetailMemberNameLabel.text=@"未填";
                        
                    }
                    else
                    {
                       _serviceDetailMemberNameLabel.text=[severDataDict.dataDict objectForKey:@"MemberName"];
                    }
                     [Global resizeForLable:_serviceDetailMemberNameLabel WithText:_serviceDetailMemberNameLabel.text parentView:self.view];
                  //  [self resizeLabel:_serviceDetailMemberNameLabel];
                    CGRect frame1=_serviceDetailGuideNameTagLabel.frame;
                    frame1.origin.x=_serviceDetailMemberNameLabel.frame.origin.x+_serviceDetailMemberNameLabel.frame.size.width+10;
                    _serviceDetailGuideNameTagLabel.frame=frame1;
                    
                    if ([severDataDict.dataDict objectForKey:@"GuideName"]!=[NSNull null]) {
                        _serviceDetailGuideNameLabel.text=[severDataDict.dataDict objectForKey:@"GuideName"];
                        // [self resizeLabel:_serviceDetailGuideNameLabel];
                        [Global resizeForLable:_serviceDetailGuideNameLabel WithText:_serviceDetailGuideNameLabel.text parentView:self.view];

                        CGRect frame1=_serviceDetailGuideNameLabel.frame;
                        frame1.origin.x=_serviceDetailGuideNameTagLabel.frame.origin.x+_serviceDetailGuideNameTagLabel.frame.size.width+1;
                        _serviceDetailGuideNameLabel.frame=frame1;
                        
                        CGRect frame2=_serviceDetailStoreNameTagLabel.frame;
                        frame2.origin.x=_serviceDetailGuideNameLabel.frame.origin.x+_serviceDetailGuideNameLabel.frame.size.width+10;
                        _serviceDetailStoreNameTagLabel.frame=frame2;
                        
                        CGRect frame3=_serviceDetailStoreNameLabel.frame;
                        frame3.origin.x=_serviceDetailStoreNameTagLabel.frame.origin.x+_serviceDetailStoreNameTagLabel.frame.size.width+1;
                        _serviceDetailStoreNameLabel.frame=frame3;

                    }
                    if ([severDataDict.dataDict objectForKey:@"StoreName"]!=[NSNull null]) {
                        _serviceDetailStoreNameLabel.text=[severDataDict.dataDict objectForKey:@"StoreName"];
                    }
                    if ([severDataDict.dataDict objectForKey:@"DocDate"]!=[NSNull null]) {
                        _serviceDetailDateLabel.text=[severDataDict.dataDict objectForKey:@"DocDate"];
                    }
                    
                    if ([severDataDict.dataDict objectForKey:@"Content"]!=[NSNull null]) {
                        _serviceDetailremarkView.text=[severDataDict.dataDict objectForKey:@"Content"];
                       // [Global resizeTextView:_serviceDetailremarkView contentStr:_serviceDetailremarkView.text];
                        CGFloat height=  [Global heightForTextView:_serviceDetailremarkView WithText:_serviceDetailremarkView.text];
                        
                        CGRect frameA=_serviceDetailremarkView.frame;
                        frameA.size.height=height;
                        _serviceDetailremarkView.frame=frameA;
                        CGRect frameD=_detailLastView.frame;
                        frameD.size.height=_serviceDetailremarkView.frame.origin.y+_serviceDetailremarkView.frame.size.height+10;
                        _detailLastView.frame=frameD;
                    }
                    if ([severDataDict.dataDict objectForKey:@"DocType"]!=[NSNull null]) {
                        NSString *statusStr =[severDataDict.dataDict objectForKey:@"DocType"];
                        _serviceDetailTypeLabel.text=[NSString stringWithFormat:@"【%@】",statusStr];
                        
                        if ([statusStr isEqualToString:@"维修"]) {
                            [_serviceDetailTypeLabel setTextColor:[UIColor colorWithRed:0xCC/255.0f green:0x66/255.0f blue:0x00/255.0f alpha:1.0f]];
                            
                        }
                        
                        else  if([statusStr isEqualToString:@"保养"])
                        {
                            [_serviceDetailTypeLabel setTextColor:[UIColor colorWithRed:0xD2/255.0f green:0xAB/255.0f blue:0x39/255.0f alpha:1.0f]];
                        }
                        
                        else
                        {
                            [_serviceDetailTypeLabel setTextColor:[UIColor colorWithRed:40.0f/255.0f green:40.0f/255.0f blue:40.0f/255.0f alpha:1.0f]];
                        }
                     //   [self resizeLabel:_serviceDetailTypeLabel];
                         [Global resizeForLable:_serviceDetailTypeLabel WithText:_serviceDetailTypeLabel.text parentView:self.view];

                        CGRect frame=_serviceDetailStatusLabel.frame;
                        frame.origin.x=_serviceDetailServiceNumLabel.frame.origin.x+_serviceDetailServiceNumLabel.frame.size.width;
                        _serviceDetailStatusLabel.frame=frame;
                    }

                    if ([severDataDict.dataDict objectForKey:@"DocStatus"]!=[NSNull null]) {
                      NSString *statusStr =[severDataDict.dataDict objectForKey:@"DocStatus"];
                        _serviceDetailStatusLabel.text=[NSString stringWithFormat:@"【%@】",statusStr];
                        
                        if ([statusStr isEqualToString:@"已结算"]) {
                            [_serviceDetailStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                            _printBtn.hidden=NO;
                        }
                        
                        else
                        {
                            _printBtn.hidden=YES;
                            [_serviceDetailStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                        }

                        CGRect frame=_serviceDetailTypeLabel.frame;
                        frame.origin.x=_serviceDetailStatusLabel.frame.origin.x+_serviceDetailStatusLabel.frame.size.width-8;
                        _serviceDetailTypeLabel.frame=frame;
                    }
                    
                    if ([severDataDict.dataDict objectForKey:@"DocTotal"]!=[NSNull null]) {
                        _serviceDetailTotalLabel.text=[NSString stringWithFormat:@"%0.02f",[[severDataDict.dataDict objectForKey:@"DocTotal"] floatValue]];
                    }
                    
                    
                    if ([severDataDict.dataDict objectForKey:@"Number"]!=[NSNull null]&&[severDataDict.dataDict objectForKey:@"GramTotal"]!=[NSNull null]) {
                        NSString *numStr=[NSString stringWithFormat:@"%d",[[severDataDict.dataDict objectForKey:@"Number"] integerValue]];
                        NSString *gramTotalStr=[NSString stringWithFormat:@"%0.02f",[[severDataDict.dataDict objectForKey:@"GramTotal"] floatValue]];
                        
                        _serviceDetailInfoLabel.text=[NSString stringWithFormat:@"购买商品信息(共%@件，%@g)",numStr,gramTotalStr];
                    }
                    
                    NSMutableArray *mDataLineArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                    
                  //  NSLog(@"mDataLineArray====%@",mDataLineArray);
                    for (int i=0; i<mDataLineArray.count; i++) {
                        [serviceDetailProductAddressArray addObject:[[mDataLineArray objectAtIndex:i] objectForKey:@"WhsName"]];
                        [serviceDetailProductNameArray addObject:[[mDataLineArray objectAtIndex:i] objectForKey:@"ItemName"]];
                         [serviceDetailCodeArray addObject:[[mDataLineArray objectAtIndex:i] objectForKey:@"ItemCode"]];
                        [serviceDetailProductUrlArray addObject:[[mDataLineArray objectAtIndex:i] objectForKey:@"ImageUrl"]];
                        [serviceDetailWeightArray addObject:[[mDataLineArray objectAtIndex:i] objectForKey:@"Gram"]];
                        [serviceDetailAttributeArray addObject:[[mDataLineArray objectAtIndex:i] objectForKey:@"Attributes"]];
                        [serviceDetailProductPriceArray addObject:[[mDataLineArray objectAtIndex:i] objectForKey:@"LineTotal"]];
                    }
                    [_serviceDetailTableView reloadData];
                    CGRect frame4=_serviceDetailTableView.frame;
                    frame4.size.height=120*serviceDetailCodeArray.count;
                    _serviceDetailTableView.frame=frame4;
                    CGRect frame5=_detailLastView.frame;
                    frame5.origin.y=_serviceDetailTableView.frame.origin.y+_serviceDetailTableView.frame.size.height+10;
                    _detailLastView.frame=frame5;
                    [_detailScrollView setContentSize:CGSizeMake(0, _detailLastView.frame.origin.y+ _detailLastView.frame.size.height+10)];
                    [_detailScrollView setScrollEnabled:YES];

                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        
                        if (_timer!=nil) {
                            [_timer invalidate];
                            _timer=nil;
                        }
                      [Global loginViewController:self noteStr:requestResultStr];
                     //   [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}
//cashierViewcontrollerDelegate
-(void)CashierAlphaViewClick
{
    if (cashierVC.view!=nil) {
        
        [cashierVC removeFromParentViewController];
        [cashierVC.view removeFromSuperview];
        
    }
    
}
-(void)CashierSuccess
{
    if (cashierVC.view!=nil) {
        
        [cashierVC removeFromParentViewController];
        [cashierVC.view removeFromSuperview];
        
    }
    [serviceNumArray removeAllObjects];
    [serviceTypeArray removeAllObjects];
    [serviceStatusArray removeAllObjects];
    [serviceNumberArray removeAllObjects];
    [serviceGuideNameArray removeAllObjects];
    [serviceMemberNameArray removeAllObjects];
    [serviceDateArray removeAllObjects];
    [serviceProductNameArray removeAllObjects];
    [servicePriceArray removeAllObjects];
    [serviceWeightArray removeAllObjects];
    _PageIndex=0;
    [self loadServiceListNextPage:_PageIndex];
}

-(void)buShouYinBtnClick:(NSUInteger)tag
{
    if (cashierVC.view!=nil) {
        
        [cashierVC removeFromParentViewController];
        [cashierVC.view removeFromSuperview];
        
    }
    cashierVC=[[CashierViewController alloc] init];
    cashierVC.delegate=self;
    cashierVC.docTypeStr=@"Service";
    cashierVC.docNumStr=[ serviceNumArray objectAtIndex:tag];
    cashierVC.view.frame = CGRectMake(0,
                                      0,
                                      self.view.bounds.size.width,
                                      self.view.bounds.size.height);
    
    [self addChildViewController:cashierVC];
    [self.view addSubview:cashierVC.view];
  //  [self.view bringSubviewToFront:cashierVC.view];
   // if (shopCartImageArray.count>0) {
//        for (int i=0; i<5; i++) {
//            UIImageView *img=(UIImageView *)[self.view viewWithTag:1000+i];
//            [img setImage:[UIImage imageNamed:@"0000.png"] ];
//            
//        }
//    _integralTextField.text=@"";
//    _deductibleTextField.text=@"";
//    _oldMeterialTextField.text=@"";
//    _cashierTextField.text=@"";
//    _bankTextField.text=@"";
//    
//    _memberAndPhoneLabel.text=@"";
//    _memberNameHiddenLabel.text=@"";
//    buShouYinCellTag=tag;
//    guideCodeStr=[Global getGuideCodeStr];
//    _guideNameLabel.text=[Global getGuideNameStr];
//    [self resizeLabel1:_guideNameLabel];
//    UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
//    [_guideListArrowImage setImage:closeImage];
//    //_memberAndPhoneLabel.text=@"";
//    _orderNumberLabel.text=@"";
//    _cashierAmountLabel.text=@"";
//    cashierAmountFloat=0.0f;
//    _integralTextField.text=@"";
//    _deductibleTextField.text=@"";
//    _oldMeterialTextField.text=@"";
//    _balancePayLabel.text=@"";
//    balanceAmountFloat=0.0f;
//    _cashierTextField.text=@"";
//    _bankTextField.text=@"";
//    _integralAvailabelLabel.text=@"";
//   serviceListCellTag=tag;
//    integralAvailabalStr=@"";
//    _integralAvailabelLabel.text=[NSString stringWithFormat:@"可用金额  ¥0.00"];
//    [UIView animateWithDuration:0.5 animations:^{
//        CGRect frame=_cashierViewContainer.frame;
//        
//        frame.origin.y=0;
//        [_cashierViewContainer setFrame:frame];
//        
//    } completion:^(BOOL finished){
//        
//    }];
//    
//    if ([Global getLoginToken].length>0) {
//        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
//        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
//        [params setObject:[Global getLoginToken] forKey:@"Token"];
//        [params setObject:@"Service" forKey:@"DocType"];
//        [params setObject:[serviceNumArray objectAtIndex:tag] forKey:@"DocNum"];
//        // NSLog(@"paramsLIST====%@",params);
//        [HttpRequest requestData:@"Guide/GatheringDetail" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
//            
//            if (isSuccess) {
//                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
//                    [Global hideProgressHUDInternal:self.view];
//                    if (_cashierTextView.text.length>0) {
//                        _cashierTextViewImage.hidden=YES;
//                        _cashierTextViewLabel.hidden=YES;
//                    }
//                    else
//                    {
//                        _cashierTextViewImage.hidden=NO;
//                        _cashierTextViewLabel.hidden=NO;
//                    }
//
//                    // NSLog(@"hhhh=%@",severDataDict.dataDict);
//                    float AvgPrice=[[severDataDict.dataDict objectForKey:@"DocTotal"] floatValue];
//                    cashierAmountFloat=[[severDataDict.dataDict objectForKey:@"DocTotal"] floatValue];
//
//                    balanceAmountFloat=AvgPrice;
//                    NSString *AvgPriceStr=[Global floatConvertPercentile:AvgPrice];
//                    _cashierAmountLabel.text=[NSString stringWithFormat:@"%@",AvgPriceStr];
//                    
//                    _orderNumberLabel.text=[severDataDict.dataDict objectForKey:@"DocNum"];
//                    _balancePayLabel.text=[NSString stringWithFormat:@"%@",AvgPriceStr];
//                    
//                    _memberInfoNoteLabel.hidden=YES;
//                    NSString *nameStr=[severDataDict.dataDict objectForKey:@"MemberName"];
//                    NSString *phoneStr=[severDataDict.dataDict objectForKey:@"Phone"];
//                    // memberCodeStr=[memberCodeArray objectAtIndex:indexPath.row];
//                    //  NSString *integralStr=[memberIntegralArray objectAtIndex:indexPath.row];
//                    _memberAndPhoneLabel.text=[NSString stringWithFormat:@"%@(%@)",nameStr,phoneStr];
//                    
//                    
//                    [self resizeLabel:_memberAndPhoneLabel];
//                    
//                    integralAvailabalStr=[NSString stringWithFormat:@"%0.02f",[[severDataDict.dataDict objectForKey:@"IntegralAmount"] floatValue]];
//                    _integralAvailabelLabel.text=[NSString stringWithFormat:@"可用金额  ¥%@",integralAvailabalStr];
//
//                    if ([severDataDict.dataDict objectForKey:@"Grade"]!= [NSNull null])
//                    {
//                        NSString *gradeStr=[severDataDict.dataDict objectForKey:@"Grade"];
//                        _memberGradeLabel.text=gradeStr;
//                        _memberGradeTagLabel.hidden=NO;
//                        _memberGradeLabel.hidden=NO;
//                        //_memberGradeLabel.text=[severDataDict.dataDict objectForKey:@"Grade"];
//                        [self resizeLabel:_memberGradeLabel];
//                    }
//
//                    CGRect frame=_memberSexImage.frame;
//                    frame.origin.x=_memberAndPhoneLabel.frame.origin.x+_memberAndPhoneLabel.frame.size.width+2;
//                    _memberSexImage.frame=frame;
//                    
//                    CGRect frame1=_memberGradeTagLabel.frame;
//                    frame1.origin.x=_memberSexImage.frame.origin.x+_memberSexImage.frame.size.width+12;
//                    _memberGradeTagLabel.frame=frame1;
//                    
//                    CGRect frame2=_memberGradeLabel.frame;
//                    frame2.origin.x=_memberGradeTagLabel.frame.origin.x+_memberGradeTagLabel.frame.size.width+2;
//                    _memberGradeLabel.frame=frame2;
//                    if ([severDataDict.dataDict objectForKey:@"Sex"]!= [NSNull null] )
//                    {
//                        NSString *sexStr1=[severDataDict.dataDict objectForKey:@"Sex"];
//                        _memberSexImage.hidden=NO;
//                        if ([sexStr1 isEqualToString:@"男"]) {
//                            [_memberSexImage setImage:[UIImage imageNamed:@"nan_.png"]];
//                        }
//                        else if ([sexStr1 isEqualToString:@"女"])
//                        {
//                            [_memberSexImage setImage:[UIImage imageNamed:@"nv_.png"]];
//                        }
//                    }
//                    
//                    if (nameStr.length==0&&phoneStr.length==0&&!([[severDataDict.dataDict objectForKey:@"Sex"] isEqualToString:@"男"]||[[severDataDict.dataDict objectForKey:@"Sex"] isEqualToString:@"女"])) {
//                        _memberInfoNoteLabel.hidden=NO;
//                        
//                    }
//                    
//
//                    
//                }
//                else
//                {
//                    [Global hideProgressHUDInternal:self.view];
//                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
//                    //  [Global showTextHud:requestResultStr view:self.view];
//                    [Global showTextHudSub:requestResultStr view:self.view];
//                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
//                        
//                        if (_timer!=nil) {
//                            [_timer invalidate];
//                            _timer=nil;
//                        }
//                        [Global loginViewController:self noteStr:requestResultStr];
//                      //  [Global loginViewController:self];
//                    }
//
//                }
//            }
//            else
//            {
//                [Global hideProgressHUDInternal:self.view];
//                [Global showTextHudSub:@"连接失败" view:self.view];
//            }
//        }];
//        
//    }
    
}
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    if (textField ==_searchProductTextField||textField ==_searchTextField) {
        return YES;
    }
    NSCharacterSet *cs;
    cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet];
    
    NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
    
    BOOL canChange = [string isEqualToString:filtered];
    
    return canChange;
}

- (void)textClick
{
   
    [_searchProductTextField becomeFirstResponder];
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    
   if (textField==_serviceMoneyTextField)
    {
        inputTextField=_serviceMoneyTextField;
        [self performSelector:@selector(serviceMoneyTextFieldBeginInput) withObject:nil afterDelay:0.1];
       
        
    }
    else if (textField==_resultTextField)
    {
        [self performSelector:@selector(textClick) withObject:nil afterDelay:0.1];
        CGRect viewFrame=_addServiceViewContainer.frame;
        viewFrame.origin.y=0;
        _addServiceViewContainer.frame=viewFrame;
        
        CGRect frame=_addServiceSearchResultViewContainer.frame;
        
        frame.origin.y=768;
        [_addServiceSearchResultViewContainer setFrame:frame];
        
//        [UIView animateWithDuration:0.5f animations:^
//         {
             CGRect frame0=_addServiceSearchProductViewContainer.frame;
             
             frame0.origin.y=0;
             [_addServiceSearchProductViewContainer setFrame:frame0];

//         }completion:^(BOOL finished) {
//             
//         }];
        
        return NO;
    }

    //
    return YES;
}
-(void)serviceMoneyTextFieldBeginInput
{
    
    [UIView animateWithDuration:0.3 animations:^{
//        CGRect viewFrame=_resultScrollView.frame;
//        viewFrame.origin.y=-(_resultView.frame.origin.y+_serviceMoneyTextField.frame.origin.y+_serviceMoneyTextField.frame.size.height-_resultScrollView.contentOffset.y+356-768);
//        _resultScrollView.frame=viewFrame;
//        
        
        
        CGFloat offset=0.0;
        CGRect frameA=_resultView.frame;
        frameA.origin.y=768-([Global getKeyboardHeight]+_serviceMoneyTextField.frame.size.height+_serviceMoneyTextField.frame.origin.y);
        offset=frameA.origin.y-_resultView.frame.origin.y+_resultScrollView.contentOffset.y;
        
        CGRect viewFrame=_resultScrollView.frame;
        viewFrame.origin.y=offset;
        _resultScrollView.frame=viewFrame;
    } completion:^(BOOL finished){
        
    }];

}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField==_serviceMoneyTextField)
    {
        [_resultScrollView setContentOffset:CGPointMake(0, 0)];
        [UIView animateWithDuration:0.3 animations:^{
            CGRect viewFrame=_resultScrollView.frame;
            viewFrame.origin.y=0;
            _resultScrollView.frame=viewFrame;
        } completion:^(BOOL finished){
            
        }];

//        [UIView animateWithDuration:0.3 animations:^{
//            CGRect viewFrame=_addServiceViewContainer.frame;
//            viewFrame.origin.y=0;
//            _addServiceViewContainer.frame=viewFrame;
//        } completion:^(BOOL finished){
//            
//        }];
        
    }

    
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
   if(textField==_searchProductTextField)
    {
        [findProductWeightArray removeAllObjects];
       [findProductImageArray removeAllObjects];
        [findMemberPhoneArray removeAllObjects];
        [findMemberNameArray removeAllObjects];
        [findMemberCodeArray removeAllObjects];
        [findMemberGradeArray removeAllObjects];
        [findMemberSexArray removeAllObjects];
       [findProductCodeArray removeAllObjects];
        [findProductNameArray removeAllObjects];
        [findProductPriceArray removeAllObjects];
        [findProductDateArray removeAllObjects];
        [findProductAddressArray removeAllObjects];
        _productPageIndex=0;
        [self loadProductNextPage:_productPageIndex];
        [_searchProductTextField resignFirstResponder];
    }
       else if (textField==_serviceMoneyTextField)
    {
        [UIView animateWithDuration:0.3 animations:^{
            CGRect viewFrame=_addServiceViewContainer.frame;
            viewFrame.origin.y=0;
            _addServiceViewContainer.frame=viewFrame;
        } completion:^(BOOL finished){
            
        }];
         [_serviceMoneyTextField resignFirstResponder];

    }
    if (textField==_searchTextField) {
        [serviceNumArray removeAllObjects];
        [serviceTypeArray removeAllObjects];
        [serviceStatusArray removeAllObjects];
        [serviceNumberArray removeAllObjects];
        [serviceGuideNameArray removeAllObjects];
        [serviceMemberNameArray removeAllObjects];
        [serviceDateArray removeAllObjects];
        [serviceProductNameArray removeAllObjects];
        [servicePriceArray removeAllObjects];
        [serviceWeightArray removeAllObjects];

        _PageIndex=0;
        [self loadServiceListNextPage:_PageIndex];
        [_searchTextField resignFirstResponder];
    }

    return YES;
}
-(void) loadProductNextPage:(NSUInteger)oldPageNum {
    if(oldPageNum!=0 && _productTotalCount<=findProductCodeArray.count)
        return;
    if(oldPageNum == 0){
        [findProductCodeArray removeAllObjects];
        [_searchProductTableView reloadData];
    }
    _productPageIndex=oldPageNum+1;
    // [self requestSeriesData:_productPageIndex pageSize:7];
    [self findProductList:_searchProductTextField.text pageIndex:_productPageIndex pageSize:6];
    
}
-(void)findProductList:(NSString *)keyWord pageIndex:(NSUInteger)pageIndex pageSize:(NSUInteger)pageSize
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:_searchProductTextField.text forKey:@"KeyWord"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:pageSize];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:pageIndex];
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
        [params setObject:@"Service" forKey:@"BType"];
        [HttpRequest requestData:@"Product/GetPItemList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    _searchNoteView.hidden=YES;
                    // NSLog(@"findProductList/////=%@",severDataDict.dataDict);
                    _productTotalCount=[[severDataDict.dataDict objectForKey:@"TotalCount"] integerValue];
                    _searchTotalLabel.text=[NSString stringWithFormat:@"共有%lu个结果",(unsigned long)_productTotalCount];
                    if (_productTotalCount%6!=0) {
                        _productTotalPage=_productTotalCount/6+1;
                    }
                    else if (_productTotalCount%6==0)
                    {
                        _productTotalPage=_productTotalCount/6;
                    }
                  NSMutableArray  *findmProducts=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    for (int i=0; i<findmProducts.count; i++) {
                        [findProductImageArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"ImageUrl"]];
                        [findProductCodeArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"ItemCode"]];
                        [findProductNameArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"ItemName"]];
                        [findProductPriceArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"Price"]];
                         [findProductWeightArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"Gram"]];
                        [findProductAddressArray  addObject:[[findmProducts objectAtIndex:i] objectForKey:@"MemberName"]];
                         [findProductDateArray  addObject:[[findmProducts objectAtIndex:i] objectForKey:@"DocDate"]];
                        [findMemberGradeArray  addObject:[[findmProducts objectAtIndex:i] objectForKey:@"Grade"]];
                         [findMemberSexArray  addObject:[[findmProducts objectAtIndex:i] objectForKey:@"Sex"]];
                        [findMemberNameArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"MemberName"]];
                        [findMemberCodeArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"MemberCode"]];
                        [findMemberPhoneArray addObject:[[findmProducts objectAtIndex:i] objectForKey:@"Phone"]];
                    }
                 
                    [_searchProductTableView reloadData];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        
                        if (_timer!=nil) {
                            [_timer invalidate];
                            _timer=nil;
                        }
                       [Global loginViewController:self noteStr:requestResultStr];
                     //   [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}

- (void)textViewDidChange:(UITextView *)textView
{
    if (textView==_resultTextView) {
        if (textView.text.length == 0) {
            _resultTextViewImage.hidden=NO;
            _resultTextViewLabel.hidden=NO;
        }
        else
        {
            _resultTextViewImage.hidden=YES;
            _resultTextViewLabel.hidden=YES;
            
        }
        
    }
  
}
-(void)textViewBeginInput
{
    
    [UIView animateWithDuration:0.3 animations:^{
//        CGRect viewFrame=_resultScrollView.frame;
//        viewFrame.origin.y=-(_resultView.frame.origin.y+_resultTextView.frame.origin.y+_resultTextView.frame.size.height-_resultScrollView.contentOffset.y+390-768);
//        _resultScrollView.frame=viewFrame;
//        
        
        CGFloat offset=0.0;
        CGRect frameA=_resultView.frame;
        frameA.origin.y=768-([Global getKeyboardHeight]+_resultTextView.frame.size.height+_resultTextView.frame.origin.y);
        offset=frameA.origin.y-_resultView.frame.origin.y+_resultScrollView.contentOffset.y;
        
        CGRect viewFrame=_resultScrollView.frame;
        viewFrame.origin.y=offset;
        _resultScrollView.frame=viewFrame;

    } completion:^(BOOL finished){
        
    }];

}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
  
   if (textView==_resultTextView) {
        [self performSelector:@selector(textViewBeginInput) withObject:nil afterDelay:0.1];
  
    }

    return YES;
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
    
  if (textView==_resultTextView) {
        [_resultScrollView setContentOffset:CGPointMake(0, 0)];
        [UIView animateWithDuration:0.3 animations:^{
            CGRect viewFrame=_resultScrollView.frame;
            viewFrame.origin.y=0;
            _resultScrollView.frame=viewFrame;
        } completion:^(BOOL finished){
            
        }];
        
    }
    
    
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView==_resultTableView) {
        return YES;
    }
    return NO;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView==_resultTableView) {
        if (editingStyle == UITableViewCellEditingStyleDelete) {
            
            [selectedProductImageArray removeObjectAtIndex:indexPath.row];
            [selectedProductWeightArray removeObjectAtIndex:indexPath.row];
            [selectedProductAddressArray removeObjectAtIndex:indexPath.row];
            [selectedProductPriceArray removeObjectAtIndex:indexPath.row];
            [selectedProductNameArray removeObjectAtIndex:indexPath.row];
            [selectedProductCodeArray removeObjectAtIndex:indexPath.row];
            
             [_resultTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            CGRect frame1=_resultTableView.frame;
            frame1.size.height=120*selectedProductCodeArray.count;
            _resultTableView.frame=frame1;
            
            CGRect frame2=_resultView.frame;
            frame2.origin.y=_resultTableView.frame.origin.y+_resultTableView.frame.size.height;
            _resultView.frame=frame2;
            
              [_resultScrollView setContentSize:CGSizeMake(0, _resultView.frame.origin.y+ _resultView.frame.size.height+25)];
            [_resultScrollView setScrollEnabled:YES];
            
            if (selectedProductCodeArray.count==0) {
                CGRect frame3=_resultTableView.frame;
                frame3.size.height=120;
                _resultTableView.frame=frame3;
                
                _resultGradeLabel.hidden=YES;
                _resultGradeTagLabel.hidden=YES;
                _resultSexImg.hidden=YES;
                _resultMemberNameAndPhoneLabel.hidden=YES;
                _resultMemberNameAndPhoneLabel.text=@"";
                _memberNoteLabel.hidden=NO;
                selectMemberCodeStr=@"";
               
                serviceTypeStr=@"";
                guideCodeStr=[Global getGuideCodeStr];
               
                _serviceMoneyTextField.text=@"";
                _resultGuideNameLabel.text=[Global getGuideNameStr];
                [Global resizeForLable:_resultGuideNameLabel WithText:_resultGuideNameLabel.text parentView:self.view];
                CGRect frameK=_resultGuideNameLabel.frame;
                frameK.origin.x=_resultGuideListArrowImage.frame.origin.x-frameK.size.width-5;
                _resultGuideNameLabel.frame=frameK;
                
                _serviceMoneyTextField
                .text=@"";
                _resultTotalValue.text=@"";
                _searchProductTextField.text=@"";
                _searchTotalLabel.text=@"共有0个结果";
                _resultNoteView.hidden=NO;
                for (int i=0; i<6; i++) {
                    UIImageView *img=(UIImageView *)[self.view viewWithTag:2000+i];
                    [img setImage:[UIImage imageNamed:@"0000.png"]];
                    
                }

                CGRect frame2=_resultView.frame;
                frame2.origin.y=_resultTableView.frame.origin.y+_resultTableView.frame.size.height;
                _resultView.frame=frame2;

            }

        }
    }
}
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
    return @"删除";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
